How to Squash Migrations?

Squashing Migrations is a time-honored practice in many ORM-adjacent systems. Examples could be on Django SO in 2016, 2017, 2020, or even the official documentation, and similar tooling in other language ecosystems, e.g. Ruby's squasher. I can't find anything about it for DrizzleKit. Has anyone done this? Is there a blog post I missed?
Stack Overflow
How to squash recent Django migrations?
In Django's migrations code, there's a squashmigrations command which: "Squashes the migrations for app_label up to and including migration_name down into fewer migrations, if possible." So, if yo...
Stack Overflow
How to squash all migration files in to one in django?
I have 82 migration files in my django app. Some of them are related to removed models. I want to merge all these 82 migration files into one migration file. How do I do without deleting the datab...
Stack Overflow
Best way to squash migrations django
I had 10 migrations and I wanted to keep them in one file . So I squash them using ./manage.py squashmigrations accounts . Now I had 11 files including init and squash file. so I deleted 9 ot...
Django Project
Django
The web framework for perfectionists with deadlines.
2 Replies
Peter Boling
Peter BolingOP•11mo ago
Indeed, searching this discord for "squash" has zero hits 🥹
Peter Boling
Peter BolingOP•11mo ago
✨ Solution! ✨ My scripts:
"scripts": {
"db:setup": "tsx src/lib/db/setup.server.ts",
"db:studio": "drizzle-kit studio --config drizzle.config.ts",
"db:generate": "drizzle-kit generate:pg --config drizzle.config.ts",
"db:migrate": "drizzle-kit push:pg --config drizzle.config.ts",
"db:squash": "rm -rf migrations/* && pnpm db:setup && pnpm db:generate && pnpm db:migrate",
"setup": "pnpm db:setup && pnpm db:migrate",
"scripts": {
"db:setup": "tsx src/lib/db/setup.server.ts",
"db:studio": "drizzle-kit studio --config drizzle.config.ts",
"db:generate": "drizzle-kit generate:pg --config drizzle.config.ts",
"db:migrate": "drizzle-kit push:pg --config drizzle.config.ts",
"db:squash": "rm -rf migrations/* && pnpm db:setup && pnpm db:generate && pnpm db:migrate",
"setup": "pnpm db:setup && pnpm db:migrate",
My src/lib/db/setup.server.ts is in this gist: https://gist.github.com/pboling/f831235a1f3c5627f0341c4bbcf37ea9#file-setup-server-ts
Gist
Squash PostgreSQL Migrations with drizzle-kit and pgtools
Squash PostgreSQL Migrations with drizzle-kit and pgtools - setup.server.ts
Want results from more Discord servers?
Add your server