diff --git a/migrations/20180430205325_update_supplier_categories_enum.js b/migrations/20180430205325_update_supplier_categories_enum.js new file mode 100644 index 000000000..c473aeca5 --- /dev/null +++ b/migrations/20180430205325_update_supplier_categories_enum.js @@ -0,0 +1,25 @@ +var constants = require('../models/constants.js'); + +exports.up = function(knex, Promise) { + // Schema + data migration for supplier categories enum + // Remap: "carriage" -> "moving", everything else -> "other" + + return Promise.all([ + knex('suppliers').whereNotIn('supplier_category', ['carriage', 'moving']).update({'supplier_category': 'other'}), + + knex.schema.alterTable(constants.SUPPLIERS_TABLE_NAME, table => { + table.enu('supplier_category', ['moving', 'other', 'carriage']).alter(); + // Temporarily add 'carriage' category for data migration + }), + + knex('suppliers').where('supplier_category', '=', 'carriage').update({supplier_category: 'moving'}), + + knex.schema.alterTable(constants.SUPPLIERS_TABLE_NAME, table => { + table.enu('supplier_category', ['moving', 'other']).alter(); + }), + ]); +}; + +exports.down = function(knex, Promise) { + +};