forked from Learn-by-doing/bitstarter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.js
43 lines (38 loc) · 1.07 KB
/
database.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
'use strict';
var config = require('./config.js');
var db = module.exports = require('knex')({
client: 'mysql',
connection: config.dbOptions
});
db.schema.hasTable('users').then(function(exists) {
if (!exists) {
return db.schema.createTable('users', function(table) {
table.increments('id');
table.string('username');
table.string('password');
table.string('email');
}).catch(console.log);
}
});
// create projects table
db.schema.hasTable('projects').then(function(exists) {
if (!exists) {
return db.schema.createTable('projects', function(table) {
table.increments('id');
table.string('name');
table.string('description');
table.decimal('goal_amount', 16,8);
}).catch(console.log);
}
});
// create addresses table
db.schema.hasTable('project_addresses').then(function(exists) {
if (!exists) {
return db.schema.createTable('project_addresses', function(table) {
table.increments('id');
table.integer('project_id').unsigned();
table.foreign('project_id').references('projects.id');
table.string('token');
}).catch(console.log);
}
});