diff --git a/migrations/000_signups_addColumn_memo_timestamp.js b/migrations/000_signups_addColumn_memo_timestamp.js new file mode 100644 index 0000000..f753526 --- /dev/null +++ b/migrations/000_signups_addColumn_memo_timestamp.js @@ -0,0 +1,51 @@ +const readline = require('readline') +const process = require('process') + +exports.up = function (knex) { + return knex.schema.hasColumn('signups', 'tmestamp').then(hasTimestamp => { + return knex.schema.hasColumn('signups', 'memo').then(hasMemo => { + if (!hasTimestamp || !hasMemo) { + + const r1 = readline.createInterface({ + input: process.stdin, + output: process.stdout + }) + return new Promise((res, rej) => { + r1.question('WARNING\n\nAbout to update your signups table. Please make sure there are no active signups. \nContinue? y/N', answer => { + if(!answer || answer === "" || answer === "n" || answer === "N"){ + rej(new Error("User aborted")) + }else{ + knex('signups').select('*').then(rows => { + return knex.schema.dropTable('signups').then(_ => { + return knex.schema.createTable('signups', function (table) { + table.increments('id').primary() + table.unique(['raidid', 'characterid']) + table.integer('raidid') + table.foreign('raidid').references('id').inTable('raids').onDelete('CASCADE') + table.integer('characterid') + table.foreign('characterid').references('id').inTable('characters').onDelete('CASCADE') + table.boolean('benched').defaultTo('false') + table.boolean('late') + table.timestamp('timestamp').defaultTo(knex.fn.now()) + table.string('memo').nullable() + return table + }).then(_ => { + knex('signups').insert(rows).then(res) + }).catch(rej) + }) + }) + } + }) + }) + } + }) + }) +} + + +exports.down = function (knex, Promise) { + return knex.schema.table('signups', function (table) { + table.dropColumn('timestamp') + table.dropColumn('memo') + }) +} \ No newline at end of file diff --git a/migrations/001_items_addColumn_stats.js b/migrations/001_items_addColumn_stats.js new file mode 100644 index 0000000..bbe980f --- /dev/null +++ b/migrations/001_items_addColumn_stats.js @@ -0,0 +1,18 @@ + +exports.up = function (knex) { + return knex.schema.hasColumn('items', 'stats').then(bool => { + if(!bool){ + return knex.schema.table('items', table => { + table.json('stats') + return table + }) + } + }) +} + + +exports.down = function (knex) { + return knex.schema.table('signups', function (table) { + table.dropColumn('stats') + }) +} \ No newline at end of file