feat(node-type-registry): extend generate-seed.ts to emit pgpm deploy/revert/verify files - #902
Merged
Merged
Conversation
…/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
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
…r with regen command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends
generate-seed.tswith a--pgpm <dir>flag that generates all three pgpm migration files (deploy, revert, verify) for thenode_type_registryseed data directly from the TypeScript node type definitions.New functions:
buildDeploySql()— deploy file with pgpm header and all 52 INSERT statements viapgsql-deparserbuildRevertSql()— revert file withDELETE FROM ... WHERE name IN (...)listing all node type namesbuildVerifySql()— verify file withSELECT 1spot-checks (one representative per category: authz, data, relation, view)All generated files include a
-- GENERATED FILE — DO NOT EDITheader with thepnpmcommand 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--singleand default modes, producing[object Promise]in output. All call sites now properlyawait.Usage:
cd graphile/node-type-registry pnpm generate:seed --pgpm ../../constructive-db/packages/metaschemaCompanion PR: constructive-io/constructive-db#694 — replaces the hand-written seed files with the generated output from this tool.
Review & Testing Checklist for Human
pnpm generate:seed --pgpm /tmp/testand diff the deploy output against the existing hand-writtenseed.sqlin constructive-db. The INSERT column order,ON CONFLICTclause, and CAST expressions should match.DELETE WHERE name IN (...)— a missing name would leave orphan rows on revert.nt.nameis 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.-- requires:dependency in the deploy header (schemas/metaschema_public/tables/node_type_registry/table) is correct for your pgpm dependency graph.Notes
writeFilehelper usesjoin(filePath, '..')instead ofpath.dirname()— functionally equivalent but slightly unconventional.GENERATED_HEADERcontains 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