pattypan
v1.0.2
Published
Squash Prisma migrations with intelligent redundancy detection
Readme
The squasher folds compatible ALTER TABLE operations into the originating
CREATE TABLE so output is a compact schema baseline (instead of appending
retained statements).
Requirements
- Node.js 18.18+ or Bun
- A Prisma project with a migrations directory such as
prisma/migrations - If you plan to run the generated Prisma metadata sync helper:
prismaand@prisma/client
Install
Run without installing:
npx pattypanIf you use Bun:
bunx pattypanInstall globally with npm:
npm install -g pattypanThen run it as:
pattypan prisma/migrationsUsage
Primary workflow (boundary-based quick pick):
npx pattypan prisma/migrationsOr, if installed globally:
pattypan prisma/migrationsIn quick mode, you:
- Pick one boundary migration from a newest-first list (page size 5).
- Tool auto-selects that migration plus all newer migrations.
- Tool opens a prechecked cherry-pick list where you can uncheck any items.
Non-interactive boundary workflow:
npx pattypan prisma/migrations --from 20240115094500_add_ordersYou can also pass a unique fragment:
npx pattypan prisma/migrations --from add_ordersOptional additive exclusions (applied after boundary selection):
npx pattypan prisma/migrations --from add_orders --exclude production_20240101,production_20240115Useful options:
--from <migration>: boundary migration name or unique fragment--exclude <patterns>: comma-separated migration filters to skip- supports
*wildcard, otherwise substring matching
- supports
--yes, -y: skip confirmation prompt--remove-dml: stripINSERT,UPDATE, andDELETEstatements from the squashed output--name <migration_name>: set output migration directory name--latest, -n <count>: legacy selection mode for latest N migrations--allow-gaps: legacy latest mode only
If selected migrations contain data-migration statements (INSERT, UPDATE, or DELETE),
Pattypan keeps them by default. Interactive runs offer a prompt to remove them, and
non-interactive runs can opt in with --remove-dml.
Output
Each squash writes:
- a new squashed
migration.sqlinside the selected output migration directory - a companion
syncPrismaMigrations.tsfile in the migrations directory root
The generated syncPrismaMigrations.ts helper is intended for existing databases where
you need to replace the selected _prisma_migrations rows with the new squashed
migration entry.
Development
If you are working on Pattypan itself:
bun installbun run buildbun testInteractive modes:
- quick mode: pick boundary migration (recommended)
- manual mode: checkbox migration selection
