Browse Source

fix migrations

master
peter 5 years ago
parent
commit
9638d500f5
2 changed files with 41 additions and 0 deletions
  1. 1
    0
      .gitignore
  2. 40
    0
      migrations/002_signups_addColumn_not_attending.js

+ 1
- 0
.gitignore View File

17
 
17
 
18
 
18
 
19
 !src/**/*
19
 !src/**/*
20
+!migrations/**/*
20
 node_modules
21
 node_modules
21
 src/frontend/node_modules
22
 src/frontend/node_modules
22
 src/frontend/out-tsc
23
 src/frontend/out-tsc

+ 40
- 0
migrations/002_signups_addColumn_not_attending.js View File

1
+const readline = require('readline')
2
+const process = require('process')
3
+
4
+
5
+exports.up = function (knex) {
6
+    return knex.schema.hasColumn('signups', 'absent').then(absent => {
7
+        if (!absent) {
8
+
9
+            const r1 = readline.createInterface({
10
+                input: process.stdin,
11
+                output: process.stdout
12
+            })
13
+            return new Promise((res, rej) => {
14
+                return knex.schema.dropTable('signups').then(_ => {
15
+                    return knex.schema.createTable('signups', function (table) {
16
+                        table.increments('id').primary()
17
+                        table.unique(['raidid', 'characterid'])
18
+                        table.integer('raidid')
19
+                        table.foreign('raidid').references('id').inTable('raids').onDelete('CASCADE')
20
+                        table.integer('characterid')
21
+                        table.foreign('characterid').references('id').inTable('characters').onDelete('CASCADE')
22
+                        table.boolean('benched').defaultTo('false')
23
+                        table.boolean('late')
24
+                        table.boolean('absent').defaultTo(false)
25
+                        table.timestamp('timestamp').defaultTo(knex.fn.now())
26
+                        table.string('memo').nullable()
27
+                        res()
28
+                    }).catch(rej)
29
+                })
30
+            })
31
+        }
32
+    })
33
+}
34
+
35
+
36
+exports.down = function (knex) {
37
+    return knex.schema.table('signups', function (table) {
38
+        table.dropColumn('absent')
39
+    })
40
+}

Loading…
Cancel
Save