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 based on folder structure. This addresses the maintainability challenge of projects with thousands of migrations in a single package.The implementation uses a path-based algorithm where change names like
schemas/auth/tables/usersare grouped into packages (e.g.,auth). Cross-package dependencies are expressed usingpackage: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, and output generationpgpm slice): Supports--dry-run, configurable depth, prefix stripping, and minimum package sizepgpm/MIGRATION_SLICING_SPEC.md): Comprehensive documentation of the algorithm and edge casesReview & Testing Checklist for Human
package:changeformat for cross-package deps - confirm this matches PGPM's expected resolution formatpgpm slice --dry-runagainst an actual large plan file to verify grouping and dependency detection work correctlyparsePlanFile()without errorspgpm slice --helpand try slicing a sample plan to verify the command works end-to-endRecommended Test Plan
pgpm slice --dry-run --plan <path>and review the output--dry-runand inspect the generatedpackages/directorypgpm.planfile is validNotes
extensions/*andmigrate/*paths are automatically assigned tocorepackageDevin run: https://app.devin.ai/sessions/e11be896d4dd45aaa746d1e2c42c186a
Requested by: @pyramation