Skip to content

feat(node-type-registry): extend generate-seed.ts to emit pgpm deploy/revert/verify files - #902

Merged
pyramation merged 2 commits into
mainfrom
devin/1774511172-generate-seed-pgpm
Mar 26, 2026
Merged

pyramation merged 2 commits into
mainfrom
devin/1774511172-generate-seed-pgpm

Conversation

@pyramation

@pyramation pyramation commented Mar 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Extends generate-seed.ts with a --pgpm <dir> flag that generates all three pgpm migration files (deploy, revert, verify) for the node_type_registry seed data directly from the TypeScript node type definitions.

New functions:

  • buildDeploySql() — deploy file with pgpm header and all 52 INSERT statements via pgsql-deparser
  • buildRevertSql() — revert file with DELETE FROM ... WHERE name IN (...) listing all node type names
  • buildVerifySql() — verify file with SELECT 1 spot-checks (one representative per category: authz, data, relation, view)

All generated files include a -- GENERATED FILE — DO NOT EDIT header with the pnpm command to regenerate them. No transaction wrappers (BEGIN/COMMIT/ROLLBACK) are emitted — pgpm handles transactions externally.

Bugfix: deparse() is async but was being called synchronously in the existing --single and default modes, producing [object Promise] in output. All call sites now properly await.

Usage:

cd graphile/node-type-registry
pnpm generate:seed --pgpm ../../constructive-db/packages/metaschema

Companion PR: constructive-io/constructive-db#694 — replaces the hand-written seed files with the generated output from this tool.

Review & Testing Checklist for Human

  • Verify generated deploy SQL matches expectations: Run pnpm generate:seed --pgpm /tmp/test and diff the deploy output against the existing hand-written seed.sql in constructive-db. The INSERT column order, ON CONFLICT clause, and CAST expressions should match.
  • Check revert SQL completeness: Confirm all 52 node type names appear in the DELETE WHERE name IN (...) — a missing name would leave orphan rows on revert.
  • String interpolation in revert/verify: nt.name is interpolated directly into SQL strings (e.g., '${nt.name}'). This is safe for current PascalCase names but would break if a name ever contained a single quote.
  • Verify the -- requires: dependency in the deploy header (schemas/metaschema_public/tables/node_type_registry/table) is correct for your pgpm dependency graph.

Notes

  • The verify file only spot-checks one node type per category (4 total). This matches the pattern in existing verify files but could be expanded if desired.
  • writeFile helper uses join(filePath, '..') instead of path.dirname() — functionally equivalent but slightly unconventional.
  • The GENERATED_HEADER contains a hardcoded relative path (../../constructive-db/packages/metaschema) which assumes the two repos are sibling directories. This is a documentation hint, not a runtime dependency.

Link to Devin session: https://app.devin.ai/sessions/267e41190f1c4710b65fa7c12cc80955
Requested by: @pyramation

…/revert/verify files

- Add --pgpm <dir> flag to generate all three pgpm migration files
- buildDeploySql(): deploy file with INSERT statements and pgpm header
- buildRevertSql(): revert file with DELETE WHERE name IN (...)
- buildVerifySql(): verify file with SELECT spot-checks per category
- Fix async/await handling for deparse() calls
- Add generate:seed npm script
@devin-ai-integration

Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@pyramation
pyramation merged commit 95ca4ae into main Mar 26, 2026
43 checks passed
@pyramation
pyramation deleted the devin/1774511172-generate-seed-pgpm branch March 26, 2026 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant