Created
March 19, 2020 17:52
-
-
Save nicholaskajoh/05532d1782d21c4d1e2e498bccda80f5 to your computer and use it in GitHub Desktop.
Knex -- add new column migration file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function up(knex) { | |
return knex.schema.table('random', (table) => { | |
table.boolean('is_deleted') | |
.defaultsTo(0) | |
.notNullable(); | |
}); | |
} | |
function down(knex) { | |
const tableName = 'random'; | |
const columnName = 'is_deleted'; | |
return knex.schema.hasColumn(tableName, columnName).then((hasColumn) => { | |
if (hasColumn) { | |
return knex.schema.table(tableName, (table) => { | |
table.dropColumn(columnName); | |
}); | |
} | |
}); | |
} | |
module.exports = { | |
up, | |
down, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment