-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added lookupModel property in most controller calls to allow using …
…a ManyToMany model. - Added tables creation and migration scripts. - Changed getRefIdField (routeHelper.js) method to return 'fileId' for any model name that contains 'File' on its name. - Fixed swaggerTestHelper to allow definitions without a required setting.
- Loading branch information
1 parent
6f09448
commit 3c73d6e
Showing
18 changed files
with
296 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* Copyright (c) 2014 TopCoder, Inc. All rights reserved. | ||
*/ | ||
/** | ||
* Represent File in the system. | ||
* | ||
* @author gfzabarino | ||
*/ | ||
'use strict'; | ||
|
||
/** | ||
* Defining ChallengeFile model | ||
*/ | ||
module.exports = function(sequelize, DataTypes) { | ||
var ChallengeFile = sequelize.define('ChallengeFile', { | ||
challengeId: { | ||
type: DataTypes.BIGINT, primaryKey: true, | ||
get: function() { | ||
return parseInt(this.getDataValue('challengeId')); | ||
} | ||
}, | ||
fileId: { | ||
type: DataTypes.BIGINT, primaryKey: true, | ||
get: function() { | ||
return parseInt(this.getDataValue('fileId')); | ||
} | ||
}, | ||
|
||
}, { | ||
tableName : 'challenge_files', | ||
associate : function(models) { | ||
ChallengeFile.belongsTo(models.Challenge, {foreignKey : 'challengeId'}); | ||
ChallengeFile.belongsTo(models.File, {foreignKey : 'fileId'}); | ||
} | ||
}); | ||
|
||
return ChallengeFile; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Copyright (c) 2014 TopCoder, Inc. All rights reserved. | ||
*/ | ||
/** | ||
* Represent File in the system. | ||
* | ||
* @author gfzabarino | ||
*/ | ||
'use strict'; | ||
|
||
/** | ||
* Defining ChallengeFile model | ||
*/ | ||
module.exports = function(sequelize, DataTypes) { | ||
var SubmissionFile = sequelize.define('SubmissionFile', { | ||
submissionId: { | ||
type: DataTypes.BIGINT, primaryKey: true, | ||
get: function() { | ||
return parseInt(this.getDataValue('submissionId')); | ||
} | ||
}, | ||
fileId: { | ||
type: DataTypes.BIGINT, primaryKey: true, | ||
get: function() { | ||
return parseInt(this.getDataValue('fileId')); | ||
} | ||
} | ||
}, { | ||
tableName : 'submission_files', | ||
associate : function(models) { | ||
SubmissionFile.belongsTo(models.Submission, {foreignKey : 'submissionId'}); | ||
SubmissionFile.belongsTo(models.File, {foreignKey : 'fileId'}); | ||
} | ||
}); | ||
|
||
return SubmissionFile; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
var dbm = require('db-migrate'); | ||
var type = dbm.dataType; | ||
var async = require('async'); | ||
|
||
exports.up = function(db, callback) { | ||
|
||
async.series([ | ||
function (callback) { | ||
// challenge files table | ||
db.createTable('challenge_files', { | ||
columns: { | ||
'"fileId"': {type: 'int', primaryKey: true}, | ||
'"challengeId"': {type: 'int', primaryKey: true} | ||
}, | ||
ifNotExists: true | ||
}, callback); | ||
}, function (callback) { | ||
// submission files table | ||
db.createTable('submission_files', { | ||
columns: { | ||
'"fileId"': {type: 'int', primaryKey: true}, | ||
'"submissionId"': {type: 'int', primaryKey: true} | ||
}, | ||
ifNotExists: true | ||
}, callback); | ||
}, function (callback) { | ||
db.runSql('ALTER TABLE challenge_files ADD CONSTRAINT challenge_fk FOREIGN KEY ("challengeId") REFERENCES challenges (id) ON UPDATE CASCADE ON DELETE CASCADE;', callback); | ||
}, function (callback) { | ||
db.runSql('ALTER TABLE submission_files ADD CONSTRAINT submission_fk FOREIGN KEY ("submissionId") REFERENCES submissions (id) ON UPDATE CASCADE ON DELETE CASCADE;', callback); | ||
}, function (callback) { | ||
db.runSql('ALTER TABLE challenge_files ADD CONSTRAINT file_fk FOREIGN KEY ("fileId") REFERENCES files (id) ON UPDATE CASCADE ON DELETE CASCADE;', callback); | ||
}, function (callback) { | ||
db.runSql('ALTER TABLE submission_files ADD CONSTRAINT file_fk FOREIGN KEY ("fileId") REFERENCES files (id) ON UPDATE CASCADE ON DELETE CASCADE;', callback); | ||
}, function (callback) { | ||
db.runSql('ALTER TABLE challenge_files ADD COLUMN "createdAt" timestamp with time zone NOT NULL;', callback); | ||
}, function (callback) { | ||
db.runSql('ALTER TABLE challenge_files ADD COLUMN "updatedAt" timestamp with time zone NOT NULL;', callback); | ||
}, function (callback) { | ||
db.runSql('ALTER TABLE submission_files ADD COLUMN "createdAt" timestamp with time zone NOT NULL;', callback); | ||
}, function (callback) { | ||
db.runSql('ALTER TABLE submission_files ADD COLUMN "updatedAt" timestamp with time zone NOT NULL;', callback); | ||
} | ||
], callback); | ||
}; | ||
|
||
exports.down = function(db, callback) { | ||
async.series([ | ||
function (callback) { | ||
db.dropTable('challenge_files', callback); | ||
}, function (callback) { | ||
db.dropTable('submission_files', callback); | ||
} | ||
], callback); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
var dbm = require('db-migrate'); | ||
var async = require('async'); | ||
var type = dbm.dataType; | ||
|
||
exports.up = function(db, callback) { | ||
console.info('migrate!!!'); | ||
db.all('SELECT "column_name" ' + | ||
'FROM "information_schema"."columns" ' + | ||
'WHERE "table_name"=\'files\' and "column_name"=\'challengeId\';', function (err, results) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
if (results && results.length) { | ||
async.series([ | ||
function (callback) { | ||
db.runSql('INSERT INTO challenge_files ("fileId", "challengeId", "createdAt", "updatedAt") ' + | ||
'SELECT id, "challengeId", "createdAt", "updatedAt" ' + | ||
'FROM files WHERE "challengeId" IS NOT NULL', callback); | ||
}, function (callback) { | ||
db.runSql('INSERT INTO submission_files ("fileId", "submissionId", "createdAt", "updatedAt") ' + | ||
'SELECT id, "submissionId", "createdAt", "updatedAt" ' + | ||
'FROM files WHERE "submissionId" IS NOT NULL', callback); | ||
}, function (callback) { | ||
db.runSql('ALTER TABLE files DROP COLUMN "submissionId"', callback); | ||
}, function (callback) { | ||
db.runSql('ALTER TABLE files DROP COLUMN "challengeId"', callback); | ||
} | ||
], callback); | ||
} else { | ||
callback(); | ||
} | ||
}); | ||
}; | ||
|
||
exports.down = function(db, callback) { | ||
callback(); | ||
}; |
Oops, something went wrong.