Is there a way to do a "down" migration with Drizzle?

I'm looking at the docs of Drizzle migrations and I can't seem to find how to write migrations that can be rolled back.
14 Replies
Blixkreeg
Blixkreeg5mo ago
remove the column from one of your tables in the drizzle schema and regenerate and migrate.
addamsson
addamsson5mo ago
i'm not sure I understand Is there an official way of downgrading?
Blixkreeg
Blixkreeg5mo ago
When you remove an attribute from the table schema, drizzle kit calculates what changed and generates the correct migration to drop the column.
addamsson
addamsson5mo ago
ah, I see, thanks so there is no built-in support
Blixkreeg
Blixkreeg5mo ago
I interpret this as built in support. But there is no way to define a down migration. It's handled for you. If you'd like to delete the migration file you can go through the steps above and then run the drop command here https://orm.drizzle.team/kit-docs/commands#drop-migration
Drizzle ORM - List of commands
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
addamsson
addamsson5mo ago
this is what I mean by up and down: https://kysely.dev/docs/migrations
Migrations | Kysely
Migration files should look like this:
addamsson
addamsson5mo ago
The problem is that there can be changes in a migration that can't be undone (custom queries and stuff like that) automatically
codeOverCoffee
codeOverCoffee5mo ago
@addamsson it is an open feature request: https://github.com/drizzle-team/drizzle-orm/discussions/1339
GitHub
Migrations Rollback · drizzle-team drizzle-orm · Discussion #1339
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...
Harley Queens™ | Conjurer
This is a huge omission
addamsson
addamsson5mo ago
there are plenty as I've discovered in the last few days when I tried to migrate my prisma project 😅
Harley Queens™ | Conjurer
The main ones for me are 1. No down migration 2. No nested operations like nested insert
addamsson
addamsson5mo ago
also no nested queries so i cant even do a n:m query with the query api kinda makes the query api useless
dj_klashndjksad
dj_klashndjksad4mo ago
Hello, I just made this small lib today that adds up and down in drizzle using some drizzle-kit internals, that they are using to make migrations work inside payloadcms. This is very early and work still in progress, but give it a try and maybe try to contribute too. https://www.npmjs.com/package/@drepkovsky/drizzle-migrations?activeTab=readme
npm
@drepkovsky/drizzle-migrations
Tiny tool for managing migrations in Drizzle. Latest version: 0.1.3, last published: a minute ago. Start using @drepkovsky/drizzle-migrations in your project by running npm i @drepkovsky/drizzle-migrations. There are no other projects in the npm registry using @drepkovsky/drizzle-migrations.
Want results from more Discord servers?
Add your server