forked from DanKottke/midas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20181220203101-add-cycle-table.js
53 lines (49 loc) · 1.58 KB
/
20181220203101-add-cycle-table.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
'use strict';
var dbm;
var type;
var seed;
/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function (options, seedLink) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
};
exports.up = function (db, callback) {
db.createTable('cycle', {
cycle_id: { type: 'bigserial', primaryKey: true },
name: { type: 'character varying', notNull: true },
posting_start_date: { type: 'timestamp with time zone' },
posting_end_date: { type: 'timestamp with time zone' },
apply_start_date: { type: 'timestamp with time zone' },
apply_end_date: { type: 'timestamp with time zone' },
cycle_start_date: { type: 'timestamp with time zone' },
cycle_end_date: { type: 'timestamp with time zone' },
community_id: { type: 'bigint', notNull: true },
created_at: { type: 'timestamp with time zone' },
updated_at: { type: 'timestamp with time zone' },
updated_by: { type: 'bigint', notNull: true },
}, (err) => {
if (err) {
callback(err);
} else {
Promise.all([
db.addForeignKey('cycle', 'community', 'cycle_community_id_fkey', {
'community_id': 'community_id',
}, { onDelete: 'RESTRICT' }),
db.addForeignKey('cycle', 'midas_user', 'cycle_updated_by_fkey', {
'updated_by': 'id',
}, { onDelete: 'RESTRICT' }),
]).then(() => {
callback();
}).catch((err) => {
callback(err);
});
}
});
};
exports.down = function (db, callback) {
db.dropTable('cycle', callback);
};