Open westernmonster opened 6 years ago
Not sure which DB this is, but if it's PostgreSQL then there's nothing much we can do about that. DDL changes in PostgreSQL aren't transactional, so you can't roll them back.
Always test your migrations in development on a throwaway DB, before rolling them out.
The same problem happended with MySQL
Some statements cannot be rolled back. In general, these include data definition language (DDL) statements, such as those that create or drop databases, those that create, drop, or alter tables or stored routines.
You should design your transactions not to include such statements. If you issue a statement early in a transaction that cannot be rolled back, and then another statement later fails, the full effect of the transaction cannot be rolled back in such cases by issuing a ROLLBACK statement.
So I guess the best practice is one ddl per migration.
@rubenv I am surprised. Postgres should support transactions around DDL. Tried it yesterday and it worked (postgres11 at least). The docs seems to confirm this: https://wiki.postgresql.org/wiki/Transactional_DDL_in_PostgreSQL:_A_Competitive_Analysis
(however it definitively does not work in mysql)
I have Same problem in mysql,How can I solve the problem?
Here is my migration file, there is a syntax error for test intentionally . When I use command line
sql-migrate up
, error occurred,migrations
table not changed, but two tables are created successfully.