feat(pgpm): add slice command for modularizing migration plans #578
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.
feat(pgpm): add slice command for modularizing migration plans
Summary
Adds a new
pgpm slicecommand that partitions a large monolithic migration plan into multiple modular packages. This addresses the maintainability challenge of projects with thousands of migrations in a single package.The implementation supports two grouping strategies:
schemas/auth/tables/users→authpackage)schemas/*_auth_*/**→authpackage)Cross-package dependencies are expressed using
package:changesyntax, and the algorithm computes a valid deployment order via topological sort.Key components:
pgpm/core/src/slice/): Dependency graph building, DAG validation, package assignment, cycle detection, pattern matching via minimatchpgpm slice): Supports--strategy,--patterns,--dry-run, configurable depth/prefix, and minimum package sizepgpm/core/__tests__/slice/slice-deploy-integration.test.ts): End-to-end test that slices plans and deploys packages to a real databasedocs/spec/SLICING.md): Comprehensive documentation of the algorithm and edge casesUpdates since last revision
pgpm/MIGRATION_SLICING_SPEC.mdtodocs/spec/SLICING.mdto follow repo conventionsReview & Testing Checklist for Human
pgpm slice --dry-runagainst an actual large plan file to verify grouping and dependency detection work correctly - unit tests may not catch real-world edge casespackage:changeformat for cross-package deps - confirm this matches PGPM's expected resolution formatpgpm slice --strategy pattern --patterns ./slices.json --dry-runto verify glob matching works correctlyparsePlanFile()without errorsRecommended Test Plan
{ "slices": [ { "packageName": "auth", "patterns": ["schemas/*_auth_*/**"] }, { "packageName": "users", "patterns": ["schemas/*_users_*/**"] } ] }--dry-runand inspect the generated packages directorypgpm.planfile is valid and deployableNotes
extensions/*andmigrate/*paths are automatically assigned tocorepackageDevin run: https://app.devin.ai/sessions/84604c65fadd4983a065f855e6c82533
Previous session: https://app.devin.ai/sessions/e11be896d4dd45aaa746d1e2c42c186a
Requested by: @pyramation