浏览代码

fix migrations

master
peter 5 年前
父节点
当前提交
9638d500f5
共有 2 个文件被更改,包括 41 次插入0 次删除
  1. 1
    0
      .gitignore
  2. 40
    0
      migrations/002_signups_addColumn_not_attending.js

+ 1
- 0
.gitignore 查看文件

@@ -17,6 +17,7 @@ log.txt
17 17
 
18 18
 
19 19
 !src/**/*
20
+!migrations/**/*
20 21
 node_modules
21 22
 src/frontend/node_modules
22 23
 src/frontend/out-tsc

+ 40
- 0
migrations/002_signups_addColumn_not_attending.js 查看文件

@@ -0,0 +1,40 @@
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
+}

正在加载...
取消
保存