Amend migrations on generation #1712
Replies: 2 comments
-
I've had this happen to me before. I don't think you really need to delete anything on your file system, drizzle takes care of that for you with the drop command. $ npx drizzle-kit drop && npx drizzle-kit generate:mysql You could even "create your own amend command in your scripts key in package.json: "scripts": {
//...
"amend": "npx drizzle-kit drop && npx drizzle-kit generate:mysql"
//...
} Edit: I didn't consider the rollback you mentioned. When I did this, I just started over with my database so I didn't need it. |
Beta Was this translation helpful? Give feedback.
-
Is there a particular reason why |
Beta Was this translation helpful? Give feedback.
-
Hello there,
I'm new to Drizzle but I am surprised that there is no way to create a unique migration for initial schema while developing a new app from scratch and iterating on the model.
Use case
When developping locally a new feature or an app from scratch, it seems usual to make mistakes and forget things. Therefore it can result in a lot of migrations doing back-and-forth between them - even if this only happens locally and never gets to production.
For example, let's say I'm developping locally a Clients database for an app:
Problem / potential improvements
In the example above, I'm getting 10-20 migrations when I could get only a migration for the final result.
It works but it's not readable, reviewable or optimal. I'd like to be able to merge them before submitting a PR for example.
That would become possible if I could amend latest migration.
Amend: Rerun a migration generation between current state C and C-2. Override the latest migration file (C-1) with the result.
Current solution
I'm currently just dropping the content of my /drizzle directory, including meta/, snapshots and migration files.
When I rerun the migration, the toolkit considers the project to be new and generates the latest state of the model in a single migration file.
However, this is not a long term solution as when the project will be deployed I'll not be able to do that again.
Proposed solution
Being able to run
npx drizzle-kit generate:mysql --amend
that would only regenerate the latest migration with the latest changes. That would allow the migration file to be clutter-free and to reduce the amount of migration files.I would link that with a rollback of the latest migration before running the amended migration.
I would also display a big warning that it should only be used in development and block the feature if NODE_ENV is set to production.
Beta Was this translation helpful? Give feedback.
All reactions