-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-teams-script.js
61 lines (58 loc) · 1.75 KB
/
add-teams-script.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
'use strict';
const management = ['connor-pearce', 'karma-gurung', 'shreya-shreeraman', 'gauraang-biyani'];
const editorial = ['mariam-raslan', 'jakob-plaschke', 'paula-brečak', 'melinda-szekeres', 'vamika-sinha', 'chiran-raj-pandey', 'daria-zahaleanu', 'seyed-mohammad-ahlesaadat', 'archita-arun', 'bernice-delos-reyes', 'liza-tait-bailey'];
const knex = require('knex')({
client: 'mysql',
connection: {
"host": "127.0.0.1",
"user": "root",
"password": "password",
"database": "the_gazelle",
"charset": "latin1"
},
});
knex('teams').insert([{
'name': 'Management',
'slug': 'management',
},
{
'name': 'Editorial',
'slug': 'editorial',
},
]).then(() => {console.log("Teams inserted successfully")});
const insert = [];
const num = management.length;
let cur = 0;
management.forEach((slug) => {
knex.select('id').from('authors').where('slug', slug).then((rows) => {
if (rows.length != 1) {
console.log("row length equals", rows.length, "at management slug:", slug);
}
insert.push({
team_id: 1,
author_id: rows[0].id,
});
cur++;
if (cur >= num) {
const ed_num = editorial.length;
let ed_cur = 0;
editorial.forEach((slug) => {
knex.select('id').from('authors').where('slug', slug).then((rows) => {
if (rows.length != 1) {
console.log("row length equals", rows.length, "at editorial slug:", slug);
}
insert.push({
team_id: 2,
author_id: rows[0].id,
});
ed_cur++;
if (ed_cur >= ed_num) {
knex('teams_authors').insert(insert).then(() => {
console.log("Inserted author team relationship");
});
}
});
});
}
});
});