-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmallDatabaseUpgrade.js
41 lines (36 loc) · 1 KB
/
smallDatabaseUpgrade.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
'use strict';
function disconnect() {
knex.destroy();
}
const knex = require('knex')({
client: 'mysql',
connection: {
host: "localhost",
user: "root",
password: "password",
database: "the_gazelle"
}
});
const MAX_NAME_OR_SLUG_LENGTH = 70;
const MAX_DESCRIPTION_LENGTH = 170;
const MAX_BIOGRAPHY_LENGTH = 255;
// Start of script
knex.schema
.table('teams', (table) => {
table.dropColumn('description');
})
.createTableIfNotExists('semesters', (table) => {
table.increments('id').primary().unsigned();
table.string('name', MAX_NAME_OR_SLUG_LENGTH).unique().notNullable();
table.date('date').unique().notNullable();
}).table('teams_authors', (table) => {
table.integer('team_order').unsigned().notNullable().defaultTo(0);
table.integer('author_order').unsigned().notNullable().defaultTo(0);
table.integer('semester_id').unsigned().references('id').inTable('semesters').onUpdate('CASCADE');
}).then(() => {
console.log("Success");
})
.catch((err) => {
throw err;
})
.then(disconnect());