Roll back the latest migration group #4617
Replies: 17 comments 24 replies
-
Traditional migration systems rely on up and down migrations to move up and down version of the DB schema. While this system is prevalent, we've learned from speaking with many developers that most of the time down migrations are not used. In a production environment, rollbacks can lead to data loss. For example: dropping a column or table that was added in a migration, and which has been exposed to users for storing data, will lead to losing this data from users. It may sound counterintuitive, but often the way to resolve this kind of situation is not by undoing the changes from the migrations but rather to fix the underlying issue, or disable the corresponding feature. Our current recommendation is to resolve issues by rolling forward: create a new migration with the changes you want. Note all of this is relevant when the migrations have been applied in other environments, i.e. production. If the migrations you want to "undo" are in development, you can always delete the migration directory, and the next time you run Removing database migration directories is of course not something you should do in production or a similar environment, i.e. staging. We are open to feedback about rollbacks (and of course about everything else): If you have strong opinions on why we should implement rollbacks please do share your thoughts with us. |
Beta Was this translation helpful? Give feedback.
-
Bom dia pessoal, Verificando os comentários, seria bom se o Prisma V2 ou posterior quando surgir, ter a opção para reverter às última migrações. No modo de desenvolvimento se deletarmos o arquivo de migração e rodar o migrate dev resolveria o problema, porém, ficaríamos sem o histórico/versionamente dessa reversão. Foi apenas meu ponto de vista e peço desculpas se eu estiver errado. Grato, |
Beta Was this translation helpful? Give feedback.
-
Any new news on this one? |
Beta Was this translation helpful? Give feedback.
-
Good night, Not. It's complicated because I've been enjoying Prisma, but I realize that I'm getting limited with some things. The difficulty of clearly documenting libraries to work with Prisma is precarious and unclear. I'm honestly thinking of removing Prisma from the project and implementing TypeORM. I have no choice because I have a deadline to meet. |
Beta Was this translation helpful? Give feedback.
-
It's definitely something you should consider to implement! Hope you didn't forget about this thread. |
Beta Was this translation helpful? Give feedback.
-
run into a similar issue with a "bad" migration that already tried to run on staging. I couldn't add a new migration to solve it cause it never got there (failing on the original bad migration).
after a commit and a push (which runs the CI/CD and the migrations), it worked. |
Beta Was this translation helpful? Give feedback.
-
+1 for being able to rollback all migrations in a single command similar to the db:migrate:undo:all in the sequelize package. I think prisma is overall better than sequelize but the ability to revert all migrations in a single command is very useful. This is what we'd like to do with our test database so we can use the same test database for multiple apps. |
Beta Was this translation helpful? Give feedback.
-
In my case I have delete a pervious migration and then run a command
|
Beta Was this translation helpful? Give feedback.
-
it is not just about feeling clever using a library but being able to ship code quickly, hope this would be implemented in the future 😞 |
Beta Was this translation helpful? Give feedback.
-
Same problem here, This rollback feature needs to there for this work. Eagerly waiting for this feature to introduced in prisma. |
Beta Was this translation helpful? Give feedback.
-
It's been a mainstay in Ruby on Rails for many years, and one of the reasons that ActiveRecord is still the best ORM out there. I'd really like to get full end-to-end Typescript, but until Prisma is up to snuff in its change management, I can't really depend on it for managing large datasets in production. |
Beta Was this translation helpful? Give feedback.
-
I often have to modify the migration content, e.g. by reviewing Pull Requests. Is there any reason why Prisma does not (or is difficult to) create a rollback command? |
Beta Was this translation helpful? Give feedback.
-
Seems like https://github.com/sequelize/sequelize supports migrate down, along with any other serious projects like RoR, Django, Go's sql-migrate https://sequelize.org/docs/v6/other-topics/migrations/#undoing-migrations |
Beta Was this translation helpful? Give feedback.
-
Down migration is easy when we do with other library, so at this time, we use other library to manage db migration. Prisma is used only for query and schema definition. We hope Prisma team has attention about this. Thank you Prisma team. |
Beta Was this translation helpful? Give feedback.
-
Hello, Ended up here after reading My conclusion is that Prisma doesn't handle the use case where we want to rollback a migration that did not fail. Only workaround I can imagine, would be:
Alternative to steps 3. and 4. could be At this point Im still unsure how I will implement that. |
Beta Was this translation helpful? Give feedback.
-
Hello, One of the most frustrating thing in this is that the documentation state that we should delete all created migration and create a new one, but this wipe the local database. So when stating this: This needs to be on the top priority. Thanks for your efforts Prisma team. Your tool is great it just need some missing feature used on every production ORM. |
Beta Was this translation helpful? Give feedback.
-
I wanted something like I've never used rollback on production (make a new migration to drop table or change column). So I agree with this comment.
However, I always use rollback in the development environment, maybe I want to tweak the name, made wrong table or something very trivial. Those are not failing migration, but I want to re-do it. It's pretty annoying if I need to reset the development db often. Maybe this feature is not so important for production use cases, but I think this kind of feature is very important for improving the developer experience, which RoR (ActiveRecord) is very good at. |
Beta Was this translation helpful? Give feedback.
-
Will Prisma Migrate support to roll back the latest migration group?
I couldn't find anything like this http://knexjs.org/#Migrations-rollback in docs.
For example:
A new version of an app includes some migrations.
It was deployed (migrations were applied) but after was made a decision to roll it back to the previous version.
What the way to roll back the last batch of migrations?
Beta Was this translation helpful? Give feedback.
All reactions