migshift is a simple interactive CLI tool that helps you rename numbered SQL migration files by shifting their numbers up or down. This is particularly useful when you need to insert new migrations between existing ones or reorder your database migration files.
- Interactive file selection using arrow keys or vim-style navigation (j/k)
- Multiple file selection support
- Pagination for large file lists
- Preserves original number formatting (leading zeros)
- Works with any SQL migration files that follow the pattern:
number_description.sql
go install github.com/bakyazi/migshift@latest-
Navigate to the directory containing your SQL migration files
-
Run the tool:
migshift
-
Use the following controls to select files:
↑/↓orj/k: Move cursorSpace: Select/deselect fileCtrl+j: Jump to first fileCtrl+k: Jump to last fileEnter: Confirm selectionq: Quit
-
After selecting files, enter a shift number:
- Positive number: Shift file numbers up
- Negative number: Shift file numbers down
Let's say you have these migration files:
001_create_users.sql
002_add_email.sql
003_add_timestamps.sql
If you want to insert a new migration between 001 and 002, you can:
- Select
002_add_email.sqland003_add_timestamps.sql - Enter shift number:
1
Result:
001_create_users.sql
002_add_email.sql -> 003_add_email.sql
003_add_timestamps.sql -> 004_add_timestamps.sql
Now you can create your new migration as 002_new_migration.sql