-
Can't find it in the docs and would like to ask if an executed migration is wrapped inside a transaction? I have a migration that will modify existing columns in several tables and I would like to understand what will happen if the it would somehow break half way through (e.g. lost connection) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 18 replies
-
Hey @AviBueno 👋 Also wrapping migrations in a transaction is considered in the future, but it's currently not implemented. |
Beta Was this translation helpful? Give feedback.
-
This is ~ impossible to implement. Each DBMS (and version) has different rules about what DDL (if any!) is subject to transactions. Lots of subtleties, like Postgres will allow a Prisma has no way to know about these issues. When Prisma generates a migration for me for Postgres that includes a CREATE INDEX, I may choose to manually edit that to add CONCURRENTLY -- that would fail if Prisma wrapped every migration in a transaction. When Prisma generates a migration for me for MySQL, Prisma has no idea what storage engine I'm using -- and I may actually use different ones in different deployments! The transactionality decisions are far outside of what Prisma can't insist on transactions unilaterally. It has to be optional, and not just at the whole-migration level -- sometimes there will be blocks that are transactional and others that aren't in one migration. There needs to be way for us as developers to indicate what should be transactional and what shouldn't. That already exists -- you manually add |
Beta Was this translation helpful? Give feedback.
-
curious - can you just wrap your generated migration code with a BEGIN and COMMIT? will that achieve the same effect here, or does prisma's rust layer make that not really work like you'd expect. |
Beta Was this translation helpful? Give feedback.
Hey @AviBueno 👋
Currently migrations are not wrapped inside a transaction, so if you break halfway, you would be left with an intermediate state, but if you run migrate again, it will start where it left from so the already performed steps would not be re-applied.
Also wrapping migrations in a transaction is considered in the future, but it's currently not implemented.