Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Trying to make database fields to be underscored #20

Open
wants to merge 2 commits into
base: db_changes
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 41 additions & 8 deletions api/models/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,20 @@ module.exports = function(sequelize, DataTypes) {
}
},
// registration start date
regStartAt: DataTypes.DATE,
regStartAt: {
type: DataTypes.DATE,
field: 'reg_start_at'
},
// submission end date
subEndAt: DataTypes.DATE,
subEndAt: {
type: DataTypes.DATE,
field: 'sub_end_at'
},
// challenge completed date
completedAt: DataTypes.DATE,
completedAt: {
type: DataTypes.DATE,
field: 'completed_at'
},
// challenge title
title: {
type: DataTypes.TEXT,
Expand All @@ -39,27 +48,51 @@ module.exports = function(sequelize, DataTypes) {
},
overview: DataTypes.STRING(140),
account: DataTypes.STRING(255),
accountId: DataTypes.STRING(255),
accountId: {
type: DataTypes.STRING(255),
field: 'account_id'
},
description: DataTypes.TEXT,
source: DataTypes.TEXT,
sourceId: DataTypes.TEXT,
sourceId: {
type: DataTypes.TEXT,
field: 'source_id'
},
tags: DataTypes.ARRAY(DataTypes.TEXT),
prizes: DataTypes.ARRAY(DataTypes.DOUBLE),
// sequelize does not support DOUBLE
prizes: DataTypes.ARRAY(DataTypes.DECIMAL(11,2)),
// the phase status of challenge
status : {
type: DataTypes.ENUM,
values: ['DRAFT', 'SUBMISSION', 'REVIEW', 'COMPLETE']
},
createdBy: DataTypes.STRING(128),
updatedBy: DataTypes.STRING(128)
createdBy: {
type: DataTypes.STRING(128),
field: 'created_by'
},
updatedBy: {
type: DataTypes.STRING(128),
field: 'updated_by'
}
}, {
tableName : 'challenges',
underscored: true,
associate : function(models) {
Challenge.hasMany(models.File);
Challenge.hasMany(models.Participant);
Challenge.hasMany(models.Submission);
Challenge.hasMany(models.Scorecard);
Challenge.hasMany(models.Requirement);
},
getterMethods: {
// FIXME
// due to sequelize 1.7 bugfix or 2.0 release we must use getters createdAt and updatedAt
createdAt: function() {
return this.getDataValue('created_at');
},
updatedAt: function() {
return this.getDataValue('updated_at');
}
}
});

Expand Down
45 changes: 36 additions & 9 deletions api/models/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,40 +23,67 @@ module.exports = function(sequelize, DataTypes) {
},
challengeId: {
type: DataTypes.BIGINT, allowNull: false,
field: 'challenge_id',
get: function() {
return parseInt(this.getDataValue('challengeId'));
}
},
submissionId: {
type: DataTypes.BIGINT, allowNull: false,
field: 'submission_id',
get: function() {
return parseInt(this.getDataValue('submissionId'));
}
},
title : {type: DataTypes.TEXT},
filePath : {type: DataTypes.TEXT, allowNull: false},
filePath : {
type: DataTypes.TEXT,
allowNull: false,
field: 'file_path'
},
size : {
type: DataTypes.BIGINT, allowNull: false,
get: function() {
return parseInt(this.getDataValue('size'));
}
},
fileName : {type: DataTypes.TEXT, allowNull: false},
fileName : {
type: DataTypes.TEXT,
allowNull: false,
field: 'file_name'
},
// file storage location
storageLocation : {
type: DataTypes.ENUM,
values: ['local', 's3'],
allowNull: false
values: ['LOCAL', 'S3'],
allowNull: false,
field: 'storage_location'
},
createdBy: DataTypes.STRING(128),
updatedBy: DataTypes.STRING(128)

createdBy: {
type: DataTypes.STRING(128),
field: 'created_by'
},
updatedBy: {
type: DataTypes.STRING(128),
field: 'updated_by'
}
}, {
tableName : 'files',
underscored: true,
associate : function(models) {
File.belongsTo(models.Challenge, {foreignKey : 'challengeId'});
File.belongsTo(models.Submission, {foreignKey : 'submissionId'});
File.belongsTo(models.Challenge, {foreignKey : 'challenge_id'});
File.belongsTo(models.Submission, {foreignKey : 'submission_id'});

},
getterMethods: {
// FIXME
// due to sequelize 1.7 bugfix or 2.0 release we must use getters createdAt and updatedAt
createdAt: function() {
return this.getDataValue('created_at');
},
updatedAt: function() {
return this.getDataValue('updated_at');
}
}
});

Expand Down
4 changes: 2 additions & 2 deletions api/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ module.exports = function(config) {
});

Object.keys(db).forEach(function(modelName) {
if (db[modelName].options.hasOwnProperty('associate')) {
db[modelName].options.associate(db);
if (db[modelName].hasOwnProperty('associate')) {
db[modelName].associate(db);
}
});
return _.extend({sequelize: sequelize, Sequelize: Sequelize}, db);
Expand Down
30 changes: 24 additions & 6 deletions api/models/participant.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,48 @@ module.exports = function(sequelize, DataTypes) {
// user id of a participant
userId : {
type: DataTypes.BIGINT, allowNull: false,
field: 'user_id',
get: function() {
return parseInt(this.getDataValue('userId'));
}
},
challengeId: {
type: DataTypes.BIGINT, allowNull: false,
field: 'challenge_id',
get: function() {
return parseInt(this.getDataValue('challengeId'));
}
},
// role of participant
role : {
type: DataTypes.ENUM,
values: ['owner', 'submitter', 'watcher', 'reviewer'],
values: ['OWNER', 'SUBMITTER', 'WATCHER', 'REVIEWER'],
allowNull: false
},
createdBy: DataTypes.STRING(128),
updatedBy: DataTypes.STRING(128)

createdBy: {
type: DataTypes.STRING(128),
field: 'created_by'
},
updatedBy: {
type: DataTypes.STRING(128),
field: 'updated_by'
}
}, {
tableName : 'participants',
underscored: true,
associate : function(models) {
Participant.belongsTo(models.User, {foreignKey : 'userId'});
Participant.belongsTo(models.Challenge, {foreignKey : 'challengeId'});
Participant.belongsTo(models.User, {foreignKey : 'user_id'});
Participant.belongsTo(models.Challenge, {foreignKey : 'challenge_id'});
},
getterMethods: {
// FIXME
// due to sequelize 1.7 bugfix or 2.0 release we must use getters createdAt and updatedAt
createdAt: function() {
return this.getDataValue('created_at');
},
updatedAt: function() {
return this.getDataValue('updated_at');
}
}
});

Expand Down
19 changes: 17 additions & 2 deletions api/models/requirement.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,31 @@ module.exports = function(sequelize, DataTypes) {
},
challengeId: {
type: DataTypes.BIGINT, allowNull: false,
field: 'challenge_id',
get: function() {
return parseInt(this.getDataValue('challengeId'));
}
},
requirementText : DataTypes.TEXT
requirementText: {
type: DataTypes.TEXT,
field: 'requirement_text'
}
}, {
tableName : 'requirements',
underscored: true,
associate : function(models) {
Requirement.belongsTo(models.Challenge, {foreignKey : 'challengeId'});
Requirement.belongsTo(models.Challenge, {foreignKey : 'challenge_id'});
Requirement.hasMany(models.ScorecardItem);
},
getterMethods: {
// FIXME
// due to sequelize 1.7 bugfix or 2.0 release we must use getters createdAt and updatedAt
createdAt: function() {
return this.getDataValue('created_at');
},
updatedAt: function() {
return this.getDataValue('updated_at');
}
}
});

Expand Down
45 changes: 37 additions & 8 deletions api/models/scorecard.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,41 @@ module.exports = function(sequelize, DataTypes) {
},
challengeId: {
type: DataTypes.BIGINT, allowNull: false,
field: 'challenge_id',
get: function() {
return parseInt(this.getDataValue('challengeId'));
}
},
// user id of reviewer
reviewerId: {
type: DataTypes.BIGINT,
field: 'reviewer_id',
get: function() {
return parseInt(this.getDataValue('reviewerId'));
}
},
submissionId: {
type: DataTypes.BIGINT,
field: 'submission_id',
get: function() {
return parseInt(this.getDataValue('submissionId'));
}
},
// sum of all the scorecard items scorecard
scoreSum: DataTypes.INTEGER,
scoreSum: {
type: DataTypes.INTEGER,
field: 'score_sum'
},
// scoreSum / scoreMax from scorecard items
scorePercent: DataTypes.FLOAT,
scorePercent: {
type: DataTypes.FLOAT,
field: 'score_percent'
},
// sum of highest possible score from scorecard items
scoreMax: DataTypes.FLOAT,
scoreMax: {
type: DataTypes.FLOAT,
field: 'score_max'
},
status : {
type: DataTypes.ENUM,
values: ['VALID', 'INVALID', 'LATE']
Expand All @@ -61,15 +73,32 @@ module.exports = function(sequelize, DataTypes) {
}
},
prize: DataTypes.FLOAT,
createdBy: DataTypes.STRING(128),
updatedBy: DataTypes.STRING(128)
createdBy: {
type: DataTypes.STRING(128),
field: 'created_by'
},
updatedBy: {
type: DataTypes.STRING(128),
field: 'updated_by'
}
}, {
tableName : 'scorecards',
underscored: true,
associate : function(models) {
Scorecard.hasMany(models.ScorecardItem);
Scorecard.belongsTo(models.Challenge, {foreignKey: 'challengeId'});
Scorecard.belongsTo(models.Submission, {foreignKey: 'submissionId'});
Scorecard.belongsTo(models.User, {foreignKey: 'reviewerId'});
Scorecard.belongsTo(models.Challenge, {foreignKey: 'challenge_id'});
Scorecard.belongsTo(models.Submission, {foreignKey: 'submission_id'});
Scorecard.belongsTo(models.User, {foreignKey: 'reviewer_id'});
},
getterMethods: {
// FIXME
// due to sequelize 1.7 bugfix or 2.0 release we must use getters createdAt and updatedAt
createdAt: function() {
return this.getDataValue('created_at');
},
updatedAt: function() {
return this.getDataValue('updated_at');
}
}
});

Expand Down
31 changes: 26 additions & 5 deletions api/models/scorecardItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,43 @@ module.exports = function(sequelize, DataTypes) {
// scorecard id of this item
scorecardId: {
type: DataTypes.BIGINT, allowNull: false,
field: 'scorecard_id',
get: function() {
return parseInt(this.getDataValue('scorecardId'));
}
},
requirementId: DataTypes.INTEGER,
requirementId: {
type: DataTypes.INTEGER,
field: 'requirement_id'
},
// score of submission
score: DataTypes.FLOAT,
// comment from reviewer
comment : DataTypes.TEXT,
createdBy: DataTypes.STRING(128),
updatedBy: DataTypes.STRING(128)
createdBy: {
type: DataTypes.STRING(128),
field: 'created_by'
},
updatedBy: {
type: DataTypes.STRING(128),
field: 'updated_by'
}
}, {
tableName : 'scorecard_items',
underscored: true,
associate : function(models) {
ScorecardItem.belongsTo(models.Scorecard, {foreignKey: 'scorecardId'});
ScorecardItem.belongsTo(models.Requirement, {foreignKey: 'requirementId'});
ScorecardItem.belongsTo(models.Scorecard, {foreignKey: 'scorecard_id'});
ScorecardItem.belongsTo(models.Requirement, {foreignKey: 'requirement_id'});
},
getterMethods: {
// FIXME
// due to sequelize 1.7 bugfix or 2.0 release we must use getters createdAt and updatedAt
createdAt: function() {
return this.getDataValue('created_at');
},
updatedAt: function() {
return this.getDataValue('updated_at');
}
}
});

Expand Down
Loading