|
| 1 | +var dbm = require('db-migrate'); |
| 2 | +var type = dbm.dataType; |
| 3 | +var async = require('async'); |
| 4 | + |
| 5 | +exports.up = function(db, callback) { |
| 6 | + |
| 7 | + async.series([ |
| 8 | + function (callback) { |
| 9 | + // challenge files table |
| 10 | + db.createTable('challenge_files', { |
| 11 | + columns: { |
| 12 | + id: {type: 'int', primaryKey: true, autoIncrement: true}, |
| 13 | + challengeId: {type: 'bigint', notNull: true}, |
| 14 | + title: {type: 'text'}, |
| 15 | + filePath: {type: 'text', notNull: true}, |
| 16 | + size: {type: 'bigint', notNull: true}, |
| 17 | + fileName: {type: 'text', notNull: true}, |
| 18 | + createdAt: {type: 'timestamp', notNull: true}, |
| 19 | + updatedAt: {type: 'timestamp', notNull: true}, |
| 20 | + createdBy: {type: 'string'}, |
| 21 | + updatedBy: {type: 'string'} |
| 22 | + }, |
| 23 | + ifNotExists: true |
| 24 | + }, callback); |
| 25 | + }, function (callback) { |
| 26 | + // submission files table |
| 27 | + db.createTable('submission_files', { |
| 28 | + columns: { |
| 29 | + id: {type: 'int', primaryKey: true, autoIncrement: true}, |
| 30 | + submissionId: {type: 'bigint', notNull: true}, |
| 31 | + title: {type: 'text'}, |
| 32 | + filePath: {type: 'text', notNull: true}, |
| 33 | + size: {type: 'bigint', notNull: true}, |
| 34 | + fileName: {type: 'text', notNull: true}, |
| 35 | + createdAt: {type: 'timestamp', notNull: true}, |
| 36 | + updatedAt: {type: 'timestamp', notNull: true}, |
| 37 | + createdBy: {type: 'string'}, |
| 38 | + updatedBy: {type: 'string'} |
| 39 | + }, |
| 40 | + ifNotExists: true |
| 41 | + }, callback); |
| 42 | + }, function (callback) { |
| 43 | + db.runSql('ALTER TABLE challenge_files ADD CONSTRAINT challenge_fk FOREIGN KEY ("challengeId") REFERENCES challenges (id) ON UPDATE CASCADE ON DELETE CASCADE;', callback); |
| 44 | + }, function (callback) { |
| 45 | + db.runSql('ALTER TABLE challenge_files ADD COLUMN "storageLocation" "enum_files_storageLocation" NOT NULL;', callback); |
| 46 | + }, function (callback) { |
| 47 | + db.runSql('ALTER TABLE submission_files ADD CONSTRAINT submission_fk FOREIGN KEY ("submissionId") REFERENCES submissions (id) ON UPDATE CASCADE ON DELETE CASCADE;', callback); |
| 48 | + }, function (callback) { |
| 49 | + db.runSql('ALTER TABLE submission_files ADD COLUMN "storageLocation" "enum_files_storageLocation" NOT NULL;', callback); |
| 50 | + } |
| 51 | + ], callback); |
| 52 | +}; |
| 53 | + |
| 54 | +exports.down = function(db, callback) { |
| 55 | + async.series([ |
| 56 | + function (callback) { |
| 57 | + db.dropTable('challenge_files', callback); |
| 58 | + }, function (callback) { |
| 59 | + db.dropTable('submission_files', callback); |
| 60 | + } |
| 61 | + ], callback); |
| 62 | +}; |
0 commit comments