migration files
This commit is contained in:
@@ -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')
|
||||
})
|
||||
}
|
||||
@@ -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')
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user