Migrations Rollback #1339
Replies: 38 comments 52 replies
-
I would love a migrate down option as well. My current approach is:
|
Beta Was this translation helpful? Give feedback.
-
If implementing an automated rollback script will take a big effort, I'd like to have a way to opt in for a manual rollback script for the time waiting for the feature. Being able to review and commit a rollback script like |
Beta Was this translation helpful? Give feedback.
-
I second that - not implementing migrations rollback/resetting is a huge omission. It's an awful pain to correct your migrations when developing schema change in a single PR doing changes on the way, since you have to delete or merge the migration files, modify the journal, revert the DB state manually and whatnot. |
Beta Was this translation helpful? Give feedback.
-
Can I pay Drizzle Team to add this? |
Beta Was this translation helpful? Give feedback.
-
Please add a rollback option for migrations :) would be awesome. |
Beta Was this translation helpful? Give feedback.
-
Don't have it yet? Wow... it's so essential! |
Beta Was this translation helpful? Give feedback.
-
Yeah this would be huge |
Beta Was this translation helpful? Give feedback.
-
Needing this feature so badly |
Beta Was this translation helpful? Give feedback.
-
Hope it releases soon |
Beta Was this translation helpful? Give feedback.
-
Just need this feature to use in production :( |
Beta Was this translation helpful? Give feedback.
-
Can we get any update on this from the drizzle team? I've posted the same in Discord, but haven't received a response. Be good to know if this is being worked on or not. Not, is fine, we'd just need to work on some approach that builds the reverse migrations using something else, but I'd be keen to know if it's something in the pipeline just to avoid recreating the wheel here. Please and thanks 🙏 |
Beta Was this translation helpful? Give feedback.
-
+1 on this, this is the only thing preventing us from using Drizzle for production as migration rollback can be crucial when deploying. |
Beta Was this translation helpful? Give feedback.
-
rollback pleaseeeee... |
Beta Was this translation helpful? Give feedback.
-
Puzzled that this is missing. I am used to the Django way, which makes managing migrations less painful. To have an equivalent is almost a must to work on larger projects in my opinion. |
Beta Was this translation helpful? Give feedback.
-
Hi, till this is implemented by drizzle team directly. |
Beta Was this translation helpful? Give feedback.
-
I was exited and about to use it in new project but without migration down it is useless for me :( |
Beta Was this translation helpful? Give feedback.
-
a migration should definitely be reversible. |
Beta Was this translation helpful? Give feedback.
-
After 3 days of using Drizzle, I was loving it until I found out there was no way to revert back without pain. Luckily for me, I'm early in my project, I hope they release this feature soon. Thanks for Drizzle though ❤️ |
Beta Was this translation helpful? Give feedback.
-
Same, was using Drizzle for the past two weeks, then migrations really started becoming an issue. It does too much magic, and a traditional up / down definition would have been significantly better. We need to be able to write business logic in our migrations and I don't see a way to do that with Drizzle other than to somehow translate Typescript code into SQL statements directly in the generated files. It's such a deal-breaker that we've moved off using Drizzle and converted everything to Kysely in the past day. Drizzle could definitely be competitive with Kysely if it got rid of its magical migrations (JSON metadata files, generated SQL files, then also a migration table?) and just allowed developers to define a Knex-style up/down mechanism. We want direct control over migrations. |
Beta Was this translation helpful? Give feedback.
-
any update on this? 👀 |
Beta Was this translation helpful? Give feedback.
-
Here are some well working examples from Laravel, Knex.js, and Lucid for https://knexjs.org/guide/migrations.html#transactions-in-migrations Knex.js:
Lucid:
Laravel:
Apart from More examples: knex migrate:latest
knex migrate:rollback
knex migrate:up 001_migration_name.js
knex migrate:list
node ace migration:rollback --batch=0
php artisan migrate:rollback --step=5 Here's a Lucid migration file: import { BaseSchema } from '@adonisjs/lucid/schema'
export default class extends BaseSchema {
protected tableName = 'users'
async up() {
this.schema.createTable(this.tableName, (table) => {
table.increments('id')
table.timestamp('created_at', { useTz: true })
table.timestamp('updated_at', { useTz: true })
})
}
async down() {
this.schema.dropTable(this.tableName)
}
} Here's a Knex.js migration file: exports.up = function (knex) {
return knex.schema
.createTable('users', function (table) {
table.increments('id');
table.string('first_name', 255).notNullable();
table.string('last_name', 255).notNullable();
})
.createTable('products', function (table) {
table.increments('id');
table.decimal('price').notNullable();
table.string('name', 1000).notNullable();
});
};
exports.down = function (knex) {
return knex.schema.dropTable('products').dropTable('users');
};
exports.config = { transaction: false }; Also, these migrations are in Typescript, not SQL, TS is more familiar and convenient to devs |
Beta Was this translation helpful? Give feedback.
-
Its crazy that this is still not supported to date. Would be nice to know if they're actually working on it. I love Drizzle and I use Neon which has DB branching feature that's really handy when it comes to situations like this. |
Beta Was this translation helpful? Give feedback.
-
Now that my application has grown more, i am experiencing the same issue. I am considering migrating back to prisma because no matter how 'fast' drizzle can be, database integrity is more important when building products that have users that care about it. |
Beta Was this translation helpful? Give feedback.
-
I'm curious how migrations will work out for SQLite? I know that right now, Drizzle isn't able to make migrations that drop columns that have FKs attached to them. It involves turning the PRAGMA off for FKs, re-creating the table, migrating all the data over (except for that column), deleting the old table, renaming the new table to the existing table name, then finally turning the PRAGMA back on This can work locally with SQLite, but I don't believe Turso (in it's current state with the LibSQL driver) can handle the PRAGMA on/off in a transaction |
Beta Was this translation helpful? Give feedback.
-
any eta on this? @AlexBlokh |
Beta Was this translation helpful? Give feedback.
-
i feel like i wana go back to knexjs or kysely |
Beta Was this translation helpful? Give feedback.
-
This. So much this. Drizzle-kit is still horridly flaky for me and seems to botch local migrations more than they work successfully. The most recent somehow only picked up some of the new tables and not others even though they're all imported properly in the schema.ts file! Dealing with botched Drizzle migrations is a huge pain in the butt due to the lack of any kind of rollback mechanism. I would HAPPILY take a Sequelize-style manual migration system over this any day of the week. Drizzle is great, but drizzle-kit is still buggy and lacking in vital features. |
Beta Was this translation helpful? Give feedback.
-
This should be a core feature of every single ORM. It is very common to write a migration and want to change something about it before actually committing/submitting the branch. I had to fix merge conflicts due to another developer creating and merging a migration before I submitted my branch, and it broke the migrations leading his to not run (since mine with the same number id already ran). Now I'm stuck manually querying the migration tracking table, but it is unclear which migration(s) I need to delete for the new one to run since they're stored with a hash, there's no way to identify which row corresponds to which migration file. I'm probably going to have to recreate my whole db just for this. |
Beta Was this translation helpful? Give feedback.
-
Hi #drizzle-team & community folks 👋
I'd like to suggest something that I believe more people might be looking for. Is there any plan for rollback migrations?
My day-to-day workflow
Because Drizzle currently doesn't support a way to rollback migrations I'm using a custom solution (hopefully temporary) with migrate with a specific
Dockerfile
configured and a more painful way to configure/deploy to run our migrations, which might be slightly painful sometimes:*.up.sql
the migration script;*.down.sql
and manually add a rollback;Dockerfile
+run.sh
script that doesn't look as pretty as I would like; 😅I was wondering if on next releases, there will be any sort migration rollback like migrate does.
This would benefit many developers and wouldn't be a breaking change by keeping everything else working.
Possible solution:
drizzle-kit generate
command;*.down.sql
;drizzle-kit
it cheks for the migrations table and identifying the latest migration ID to match with a<migration_name>.down.sql
script on the folder to be executed otherwise exit;drizzle-kit rollback:*
/drizzle-kit undo:*
command;The future
Using Drizzle is being a breazy so far (coming from Knex) and I wanna see what things going far beyond the rest of the community.
Let's see how the community will (or not) react to this idea (calling for help) and also the core team.
Beta Was this translation helpful? Give feedback.
All reactions