-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfillSmallDatabaseUpgrade.js
76 lines (71 loc) · 1.57 KB
/
fillSmallDatabaseUpgrade.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
'use strict';
function disconnect() {
knex.destroy();
}
const knex = require('knex')({
client: 'mysql',
connection: {
host: "localhost",
user: "root",
password: "password",
database: "the_gazelle"
},
});
const author_order = [
{id: 10, author_order: 0},
{id: 11, author_order: 1},
{id: 12, author_order: 2},
{id: 15, author_order: 3},
{id: 14, author_order: 4},
{id: 6, author_order: 5},
{id: 7, author_order: 6},
{id: 13, author_order: 7},
{id: 8, author_order: 8},
{id: 9, author_order: 9},
{id: 5, author_order: 10},
{id: 1, author_order: 0},
{id: 2, author_order: 1},
{id: 3, author_order: 2},
{id: 4, author_order: 3},
];
knex('semesters').insert([{name: "Spring 2017", date: "2017-02-01"}])
.then(() => {
let done = 0;
knex('teams_authors').where('team_id', '=', 1)
.update('team_order', 0)
.then(() => {
done++;
if (done >= 18) {
console.log("success");
knex.destroy();
}
});
knex('teams_authors').update('semester_id', 1)
.then(() => {
done++;
if (done >= 18) {
console.log("success");
knex.destroy();
}
});
knex('teams_authors').where('team_id', '=', 2)
.update('team_order', 1)
.then(() => {
done++;
if (done >= 18) {
console.log("success");
knex.destroy();
}
});
author_order.forEach((object) => {
knex('teams_authors').where('id', '=', object.id)
.update('author_order', object.author_order)
.then(() => {
done++;
if (done >= 18) {
console.log("success");
knex.destroy();
}
});
});
});