You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

000_signups_addColumn_memo_timestamp.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. const readline = require('readline')
  2. const process = require('process')
  3. exports.up = function (knex) {
  4. return knex.schema.hasColumn('signups', 'tmestamp').then(hasTimestamp => {
  5. return knex.schema.hasColumn('signups', 'memo').then(hasMemo => {
  6. if (!hasTimestamp || !hasMemo) {
  7. const r1 = readline.createInterface({
  8. input: process.stdin,
  9. output: process.stdout
  10. })
  11. return new Promise((res, rej) => {
  12. r1.question('WARNING\n\nAbout to update your signups table. Please make sure there are no active signups. \nContinue? y/N', answer => {
  13. if(!answer || answer === "" || answer === "n" || answer === "N"){
  14. rej(new Error("User aborted"))
  15. }else{
  16. knex('signups').select('*').then(rows => {
  17. return knex.schema.dropTable('signups').then(_ => {
  18. return knex.schema.createTable('signups', function (table) {
  19. table.increments('id').primary()
  20. table.unique(['raidid', 'characterid'])
  21. table.integer('raidid')
  22. table.foreign('raidid').references('id').inTable('raids').onDelete('CASCADE')
  23. table.integer('characterid')
  24. table.foreign('characterid').references('id').inTable('characters').onDelete('CASCADE')
  25. table.boolean('benched').defaultTo('false')
  26. table.boolean('late')
  27. table.timestamp('timestamp').defaultTo(knex.fn.now())
  28. table.string('memo').nullable()
  29. return table
  30. }).then(_ => {
  31. knex('signups').insert(rows).then(res)
  32. }).catch(rej)
  33. })
  34. })
  35. }
  36. })
  37. })
  38. }
  39. })
  40. })
  41. }
  42. exports.down = function (knex, Promise) {
  43. return knex.schema.table('signups', function (table) {
  44. table.dropColumn('timestamp')
  45. table.dropColumn('memo')
  46. })
  47. }