For any reason some migration might fail at some point. I was under the impression that migrations are wrapped in transactions in knex however to my dismay i realised that even though the migration has failed, the tables that were created before the error still persist in the DB.
An example migration would look like this:
exports.up = function (knex) {
return knex.schema
.createTable('someTable', function (table) {
table.increments('id');
table.string('something').notNullable();
//throws error here for whatever reason, maybe an invalid default value
})
.createTable('another table', function (table) {
table.increments('id');
table.string('other').notNullable();
})
};
exports.down = function (knex) {
return knex.schema
.dropTable("chatGroups")
.dropTable("chatMessages");
};
Even though the error is thrown when creating someTable nothing rolls back and all changes are commited to the DB. Running the migration subsequently is now not possible. Even worse, it is not registered in knex_migrations and i cannot even rollback so i have to delete the table manually.
Am i missing something? I would like things to happen atomically, how can i achieve that?
Thank you so much