Browse Source

migration files

master
peter 5 years ago
parent
commit
1cf5289fa6

+ 51
- 0
migrations/000_signups_addColumn_memo_timestamp.js View File

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

+ 18
- 0
migrations/001_items_addColumn_stats.js View File

@@ -0,0 +1,18 @@
1
+
2
+exports.up = function (knex) {
3
+    return knex.schema.hasColumn('items', 'stats').then(bool => {
4
+        if(!bool){
5
+            return knex.schema.table('items', table => {
6
+                table.json('stats')
7
+                return table
8
+            })
9
+        }
10
+    })
11
+}
12
+
13
+
14
+exports.down = function (knex) {
15
+    return knex.schema.table('signups', function (table) {
16
+        table.dropColumn('stats')
17
+    })
18
+}

Loading…
Cancel
Save