Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nicholaskajoh/05532d1782d21c4d1e2e498bccda80f5 to your computer and use it in GitHub Desktop.
Save nicholaskajoh/05532d1782d21c4d1e2e498bccda80f5 to your computer and use it in GitHub Desktop.
Knex -- add new column migration file.
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