feat(pgpm): pgpm import — pgpm-itize an arbitrary SQL dump (Part A of #1340) - #1571
Merged
Conversation
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:
|
…al sequences, OWNED BY, late ALTERs, and seed FKs
… in --partition support
…tioned imports deploy in order
pgpm import — pgpm-itize a SQL dump through the dials pipeline…preamble psql meta-commands in pgpm import
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
Part A of constructive-planning#1340 (three-dial roadmap: constructive-planning#1329): a file/dump front door into the dials substrate.
pgpm importturns a realpg_dumpoutput (or a directory of.sqlfiles, concatenated in sorted filename order) into a complete deployable pgpm module — module dir,.control,pgpm.plan, deploy/revert/verify trees with spec-derived paths, graph-derived requires, and generated revert/verify.This branch merges two implementations: the initial line-regex sanitizing driver and the spec-complete driver, keeping the spec behavior (
--pkg, defaultobjectgranularity, COPY blocks as units, riders preserved and attached to hosts,misc/fallback, directory input,--with-data) and folding in--partitionsupport from the first.Pipeline
@pgpmjs/export:dump-source.ts—loadDumpSource/preprocessDumpText: strips psql backslash commands (outside dollar-quoted bodies), extractsCOPY ... FROM stdinblocks atomically through the terminating\., andcopyBlockToInsertconverts COPY rows to multi-row INSERTs (pgpm's deploy driver doesn't stream COPY stdin).import.ts—importDumpRows: classify (classifyStatements) → restructure through the sharedrestructureExportRowsseam → rows. Dump-specific handling:SET ...,set_config(...)) skipped and counted;COMMENT ON/GRANT/ownership kept as riders attached to their host object; lateALTER TABLE ONLY ... ADD CONSTRAINTfolds at object/consolidated.CREATE EXTENSION→.controlrequires(pgpm owns extension creation).setval) skipped by default with a warning;--with-dataemits seed fixture changes with FK-ordered seed deps.ALTER SEQUENCE ... OWNED BY table.colrides the table change (the sequence deploys before its table exists otherwise); serialnextval('seq')defaults get explicit sequence deps (plain-string refs the statement graph can't see); rows are topo-sorted so the plan deploys in order.misc/statementschange with a warning — never dropped silently. Summary printed: N statements → M changes, K warnings.linkTextualDeps— post-partition fixup: re-links rider/serial deps that only exist in statement text afterpartitionUnitsregroups statements, pruning cycle-forming back-edges so partitioned plans stay deployable.pgpm/cli:commands/import.ts— the command;--partition <config>reusespartitionExportRows(same config shape aspgpm transform/pgpm export --partition) to split the import into multiple packages with cross-packagerequires.utils/emit-package.ts— module emission (writePackage/writeControlFile/checkOverwrite) factored out oftransform.tsand shared by import/transform, per the feat(pgpm):pgpm transform— re-dial an existing module/workspace; wire--partitionintopgpm export#1569 convergence note.Tests
--with-data, seed FK ordering, collision paths, flat naming (32 tests).pg_dumpfixture (preamble, 2 schemas, FKs, serial + standalone sequences, function, trigger, RLS policy, grants, comments, extension, COPY data). For each granularity: import → deploy into a fresh DB → catalog equivalence with the source (snapshotCatalog/diffCatalogSnapshots) →pgpm verify→pgpm revertleaves the DB clean. Plus--dry-run,--with-data(seeds land, sequence state continues), and--partition(two packages, cross-package requires, deploys to an equivalent catalog).Refs: constructive-planning#1340 (Part A), constructive-planning#1329; emit path shared with #1569 (
pgpm transform).Link to Devin session: https://app.devin.ai/sessions/f54bc87f17d748b6a143280e0ace5ba6
Requested by: @pyramation