Skip to content

Commit

Permalink
Add migration for script_options.
Browse files Browse the repository at this point in the history
  • Loading branch information
bchrobot committed Jun 25, 2019
1 parent 2374d20 commit b75ef0d
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions migrations/20190625124200_add_interaction_step_script_options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Add script_options column to interaction_step
exports.up = function(knex, Promise) {
return knex.schema
.alterTable("interaction_step", table => {
table.specificType("script_options", "text ARRAY").nullable();
})
.then(() =>
// Backfill values
knex("interaction_step").update({
script_options: knex.raw("ARRAY[script]")
})
)
.then(() =>
// Make not nullable
knex.schema.alterTable("interaction_step", table => {
table
.specificType("script_options", "text ARRAY")
.notNullable()
.alter();
})
)
.then(() =>
knex.schema.alterTable("interaction_step", table => {
table.dropColumn("script");
})
);
};

// Drop script_options column to interaction_step
exports.down = function(knex, Promise) {
return knex.schema
.alterTable("interaction_step", table => {
table
.text("script")
.notNullable()
.defaultTo("");
})
.then(() =>
knex("interaction_step").update({
script: knex.raw("script_options[0]")
})
)
.then(() =>
knex.schema.alterTable("interaction_step", table => {
table.dropColumn("script_options");
})
);
};

0 comments on commit b75ef0d

Please sign in to comment.