Skip to content

Conversation

@pyramation
Copy link
Contributor

feat(pgpm): add slice command for modularizing migration plans

Summary

Adds a new pgpm slice command 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/users are grouped into packages (e.g., auth). Cross-package dependencies are expressed using package:change syntax, and the algorithm computes a valid deployment order via topological sort.

Key components:

  • Core slicing logic (pgpm/core/src/slice/): Dependency graph building, DAG validation, package assignment, cycle detection, and output generation
  • CLI command (pgpm slice): Supports --dry-run, configurable depth, prefix stripping, and minimum package size
  • Design spec (pgpm/MIGRATION_SLICING_SPEC.md): Comprehensive documentation of the algorithm and edge cases

Review & Testing Checklist for Human

  • Verify cross-package dependency syntax: The code generates package:change format for cross-package deps - confirm this matches PGPM's expected resolution format
  • Test with a real plan file: Run pgpm slice --dry-run against an actual large plan file to verify grouping and dependency detection work correctly
  • Validate generated plan files: Ensure output plan files can be parsed back by parsePlanFile() without errors
  • Check deploy order correctness: For complex dependency chains, verify packages are ordered correctly (dependencies before dependents)
  • Test CLI manually: Run pgpm slice --help and try slicing a sample plan to verify the command works end-to-end

Recommended Test Plan

  1. Find or create a plan file with 10+ changes across multiple schemas
  2. Run pgpm slice --dry-run --plan <path> and review the output
  3. Run without --dry-run and inspect the generated packages/ directory
  4. Verify each generated pgpm.plan file is valid

Notes

  • 18 unit tests pass covering core slicing functions
  • The algorithm warns but proceeds when package cycles are detected (may want stricter handling)
  • extensions/* and migrate/* paths are automatically assigned to core package

Devin run: https://app.devin.ai/sessions/e11be896d4dd45aaa746d1e2c42c186a
Requested by: @pyramation

- Add core slicing logic in pgpm/core/src/slice/ with path-based grouping
- Implement folder-based strategy to extract package names from change paths
- Add dependency graph building, validation, and topological sorting
- Generate cross-package dependencies using package:change syntax
- Add slice command to pgpm CLI with dry-run and configuration options
- Include comprehensive test suite with 18 passing tests
- Add detailed design specification document
@devin-ai-integration
Copy link
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

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.

2 participants