Skip to content

microsoft/power-platform-skills / plugins/power-pages/skills/setup-datamodel

setup-datamodel

Verified

Creates Dataverse tables, columns, and relationships for a Power Pages site based on a data model proposal. Supports SPA sites and PAC-downloaded non-SPA sites. Use when the user wants to set up the data model, create database tables, or build the Dataverse schema for their site.

scripts/validate-datamodel.js

View on GitHub
#!/usr/bin/env node

// Validates Dataverse data model creation output.
// Runs as a PostToolUse(Skill) hook to verify tables and columns were properly created.
// Reads .datamodel-manifest.json (written by the setup-datamodel skill) and
// queries the Dataverse OData API to confirm each table/column exists.

const fs = require('fs');
const path = require('path');
const { approve, block, runValidation, findPath, getAuthToken, makeRequest, getEnvironmentUrl } = require('../../../scripts/lib/validation-helpers');

runValidation(async (cwd) => {
  const manifestPath = findPath(cwd, '.datamodel-manifest.json');
  if (!manifestPath) approve(); // Not a data model session, skip

  const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
  if (!manifest.tables || manifest.tables.length === 0) approve();

  const envUrl = manifest.environmentUrl || getEnvironmentUrl();
  if (!envUrl) approve(); // Can't determine environment — don't block

  const token = getAuthToken(envUrl);
  if (!token) approve(); // Auth not available — don't block

  const errors = [];

  for (const table of manifest.tables) {
    const tableExists = await checkTableExists(envUrl, token, table.logicalName);
    if (!tableExists) {
      errors.push(`Missing table: ${table.logicalName} (${table.displayName || 'unknown'})`);
      continue;
    }

    if (table.columns && table.columns.length > 0) {
      const existingColumns = await getTableColumns(envUrl, token, table.logicalName);
      for (const col of table.columns) {
        if (!existingColumns.includes(col.logicalName)) {
          errors.push(`Missing column: ${table.logicalName}.${col.logicalName}`);
        }
      }
    }
  }

  if (errors.length > 0) {
    block('Dataverse data model validation failed:\n- ' + errors.join('\n- '));
  }

  approve();
});

async function checkTableExists(envUrl, token, logicalName) {
  try {
    const result = await makeRequest({
      url: `${envUrl}/api/data/v9.2/EntityDefinitions(LogicalName='${logicalName}')`,
      headers: {
        Authorization: `Bearer ${token}`,
        Accept: 'application/json',
      },
      timeout: 15000,
    });
    return result.statusCode === 200;
  } catch {
    return false;
  }
}

async function getTableColumns(envUrl, token, logicalName) {
  try {
    const result = await makeRequest({
      url: `${envUrl}/api/data/v9.2/EntityDefinitions(LogicalName='${logicalName}')/Attributes?$select=LogicalName`,
      headers: {
        Authorization: `Bearer ${token}`,
        Accept: 'application/json',
      },
      timeout: 15000,
    });
    if (result.error || result.statusCode !== 200) return [];
    const parsed = JSON.parse(result.body);
    return (parsed.value || []).map((a) => a.LogicalName).filter(Boolean);
  } catch {
    return [];
  }
}
deprecation-and-migrationaddyosmani/agent-skillsManages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
performance-optimizationaddyosmani/agent-skillsOptimizes application performance across frontend, backend, queries, and databases. Use when performance requirements exist, when you suspect performance regressions, when Core Web Vitals or load times need improvement, when N+1 query patterns need fixing, or when profiling reveals bottlenecks.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.Stars: 118kUpdated Claude CodeCodexVerifiedInstall
agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.Stars: 118kUpdated Claude CodeCodexVerifiedInstall