chore: updating migrations again and making simpler
Signed-off-by: benjdlambert <ben@blam.sh>
This commit is contained in:
@@ -22,25 +22,7 @@
|
||||
exports.up = async function up(knex) {
|
||||
await knex.schema.alterTable('user_info', table => {
|
||||
table.renameColumn('exp', 'updated_at');
|
||||
});
|
||||
|
||||
// Sqlite doesn't support adding a column with non-constant default when table has data
|
||||
// so we need to add it as nullable first, then set the value to the updated_at value
|
||||
await knex.schema.alterTable('user_info', table => {
|
||||
table.timestamp('created_at').nullable();
|
||||
});
|
||||
|
||||
await knex('user_info').update({
|
||||
created_at: knex.ref('updated_at'),
|
||||
});
|
||||
|
||||
// Then alter to non-nullable and set the default to now()
|
||||
await knex.schema.alterTable('user_info', table => {
|
||||
table
|
||||
.timestamp('created_at')
|
||||
.notNullable()
|
||||
.defaultTo(knex.fn.now())
|
||||
.alter();
|
||||
table.timestamp('created_at').notNullable().defaultTo(knex.fn.now());
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user