Squashing AdonisJS Migrations: A Tool I Built
The Problem
After years of development, AdonisJS projects often accumulate hundreds of migration files:
- ๐ Slow fresh deployments (running 100+ migrations)
- ๐ Cluttered migration folders
- ๐ Hard to understand current schema
- ๐งน No official way to consolidate like Django’s
squashmigrations
The Solution
I built adonis-lucid-migration-squash to solve this!
What it does:
Takes your PostgreSQL schema dump and converts it to a clean, single Knex migration with:
- โ Smart enum detection
- โ Proper foreign keys & constraints
- โ Automated verification
- โ Complete up() and down() methods
Quick Start:
# 1. Dump your production schema
pg_dump -s --no-owner --no-acl > schema.sql
# 2. Convert to Knex migration
python -m pg_to_knex schema.sql baseline_migration.ts
# 3. Archive old migrations, use the baseline!
mv database/migrations/*.ts database/archive/
mv baseline.ts database/migrations/1_baseline.ts
Example Output:
Instead of raw SQL, you get clean Knex code:
export async function up(knex: Knex) {
await knex.schema.createTable('users', (table) => {
table.uuid('id').primary()
table.string('email').notNullable().unique()
table.enum('role', ['admin', 'user']).defaultTo('user')
table.timestamps(true, true)
})
}
When to use it?
โ
Before major version releases
โ
When you have 50+ migrations
โ
Creating a clean foundation
โ
All environments are on the same version
Check it out!
๐ GitHub Would love to hear feedback from the AdonisJS community! ๐ #adonisjs #nodejs #typescript #database #migrations