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

Db changes #18

Open
wants to merge 8 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
1 change: 1 addition & 0 deletions api/models/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ module.exports = function(sequelize, DataTypes) {
updatedBy: DataTypes.STRING(128)
}, {
tableName : 'challenges',
underscored : true,
associate : function(models) {
Challenge.hasMany(models.File);
Challenge.hasMany(models.Participant);
Expand Down
1 change: 1 addition & 0 deletions api/models/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ module.exports = function(sequelize, DataTypes) {

}, {
tableName : 'files',
underscored: true,
associate : function(models) {
File.belongsTo(models.Challenge, {foreignKey : 'challengeId'});
File.belongsTo(models.Submission, {foreignKey : 'submissionId'});
Expand Down
3 changes: 2 additions & 1 deletion api/models/participant.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module.exports = function(sequelize, DataTypes) {

}, {
tableName : 'participants',
underscored: true,
associate : function(models) {
Participant.belongsTo(models.User, {foreignKey : 'userId'});
Participant.belongsTo(models.Challenge, {foreignKey : 'challengeId'});
Expand All @@ -53,4 +54,4 @@ module.exports = function(sequelize, DataTypes) {

return Participant;

};
};
1 change: 1 addition & 0 deletions api/models/requirement.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module.exports = function(sequelize, DataTypes) {
requirementText : DataTypes.TEXT
}, {
tableName : 'requirements',
underscored : true,
associate : function(models) {
Requirement.belongsTo(models.Challenge, {foreignKey : 'challengeId'});
Requirement.hasMany(models.ScorecardItem);
Expand Down
1 change: 1 addition & 0 deletions api/models/scorecard.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ module.exports = function(sequelize, DataTypes) {
updatedBy: DataTypes.STRING(128)
}, {
tableName : 'scorecards',
underscored : true,
associate : function(models) {
Scorecard.hasMany(models.ScorecardItem);
Scorecard.belongsTo(models.Challenge, {foreignKey: 'challengeId'});
Expand Down
1 change: 1 addition & 0 deletions api/models/scorecardItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = function(sequelize, DataTypes) {
updatedBy: DataTypes.STRING(128)
}, {
tableName : 'scorecard_items',
underscored : true,
associate : function(models) {
ScorecardItem.belongsTo(models.Scorecard, {foreignKey: 'scorecardId'});
ScorecardItem.belongsTo(models.Requirement, {foreignKey: 'requirementId'});
Expand Down
3 changes: 2 additions & 1 deletion api/models/submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = function(sequelize, DataTypes) {
updatedBy: DataTypes.STRING(128)
}, {
tableName : 'submissions',
underscored : true,
associate : function(models) {
Submission.hasMany(models.File);
Submission.hasMany(models.Scorecard);
Expand All @@ -48,4 +49,4 @@ module.exports = function(sequelize, DataTypes) {

return Submission;

};
};
1 change: 1 addition & 0 deletions api/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = function(sequelize, DataTypes) {
updatedBy: DataTypes.STRING(128)
}, {
tableName : 'users',
underscored : true,
associate : function(models) {
User.hasMany(models.Participant);
User.hasMany(models.Scorecard);
Expand Down
10 changes: 5 additions & 5 deletions api/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1571,10 +1571,10 @@ definitions:
type: string
description: The role the participant has on the challenge
enum:
- owner
- submitter
- watcher
- reviewer
- OWNER
- SUBMITTER
- WATCHER
- REVIEWER
createdAt:
type: string
format: date-time
Expand Down Expand Up @@ -1941,4 +1941,4 @@ definitions:
description: The http status code
content:
type: string
description: The error message
description: The error message
8 changes: 4 additions & 4 deletions config/schema-migrations/20141010150000-enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ exports.up = function (db, callback) {
db.runSql.bind(db,
"CREATE TYPE enum_challenges_status AS ENUM ( 'DRAFT', 'SUBMISSION', 'REVIEW', 'COMPLETE');"),
db.runSql.bind(db,
"CREATE TYPE \"enum_files_storageLocation\" AS ENUM ('local', 's3');"),
"CREATE TYPE \"enum_files_storage_location\" AS ENUM ('LOCAL', 'S3');"),
db.runSql.bind(db,
"CREATE TYPE enum_participants_role AS ENUM ('owner', 'submitter', 'watcher', 'reviewer');"),
"CREATE TYPE enum_participants_role AS ENUM ('OWNER', 'SUBMITTER', 'WATCHER', 'REVIEWER');"),
db.runSql.bind(db,
"CREATE TYPE enum_scorecards_status AS ENUM ('VALID', 'INVALID', 'LATE');")
], callback);
Expand All @@ -18,8 +18,8 @@ exports.up = function (db, callback) {
exports.down = function (db, callback) {
async.series([
db.runSql.bind(db, "DROP TYPE enum_challenges_status;"),
db.runSql.bind(db, "DROP TYPE \"enum_files_storageLocation\";"),
db.runSql.bind(db, "DROP TYPE \"enum_files_storage_location\";"),
db.runSql.bind(db, "DROP TYPE enum_participants_role;"),
db.runSql.bind(db, "DROP TYPE enum_scorecards_status;")
], callback);
};
};
211 changes: 99 additions & 112 deletions config/schema-migrations/20141010160840-tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,133 +5,120 @@ var type = dbm.dataType;
exports.up = function (db, callback) {
async.series([
// challenges table
db.createTable.bind(db, 'challenges', {
id: { type: 'int', primaryKey: true, autoIncrement: true, notNull: true },
reg_start_at: { type: 'timestamp' },
sub_end_at: { type: 'timestamp' },
completed_at: { type: 'timestamp' },
title: { type: 'text', notNull: true, defaultValue: "Untitled Challenge" },
overview: { type: 'string', length: 140 },
description: { type: 'text' },
account: { type: 'string', length: 255 },
account_id: { type: 'string', length: 255 },
source: { type: 'text' },
source_id: { type: 'text' },
created_at: { type: 'timestamp', notNull: true },
updated_at: { type: 'timestamp', notNull: true },
created_by: { type: 'string', length: 128 },
updated_by: { type: 'string', length: 128 }
}),
db.runSql.bind(db,
'CREATE TABLE challenges ( ' +
'id bigserial NOT NULL, ' +
'"regStartAt" timestamp with time zone, ' +
'"subEndAt" timestamp with time zone, ' +
'"completedAt" timestamp with time zone, ' +
'title text NOT NULL DEFAULT \'Untitled Challenge\'::text, ' +
'overview character varying(140), ' +
'description text, ' +
'tags text[], ' +
'prizes NUMERIC(11,2)[], ' +
'account character varying(255), ' +
'"accountId" character varying(255), ' +
'"source" text, ' +
'"sourceId" text, ' +
'status enum_challenges_status NOT NULL, ' +
'"createdAt" timestamp with time zone NOT NULL, ' +
'"updatedAt" timestamp with time zone NOT NULL, ' +
'"createdBy" character varying(128), ' +
'"updatedBy" character varying(128) ' +
');'),
db.runSql.bind(db, 'ALTER TABLE ONLY challenges ADD CONSTRAINT challenges_pkey PRIMARY KEY (id);'),

"ALTER TABLE challenges ADD COLUMN tags text[]," +
"ADD COLUMN prizes NUMERIC(11, 2)[]," +
"ADD COLUMN status enum_challenges_status NOT NULL;"),

// files table
db.createTable.bind(db, 'files', {
'id': { type: 'int', primaryKey: true, autoIncrement: true, notNull: true },
'title': { type: 'text' },
'file_path': { type: 'text', notNull: true },
'size': { type: 'bigint', notNull: true },
'file_name': { type: 'text', notNull: true },
'created_at': { type: 'timestamp', notNull: true },
'updated_at': { type: 'timestamp', notNull: true },
'created_by': { type: 'string', length: 128 },
'updated_by': { type: 'string', length: 128 },
'submission_id': { type: 'bigint' },
'challenge_id': { type: 'bigint', notNull: true}
}),
db.runSql.bind(db,
'CREATE TABLE files ( ' +
'id bigserial NOT NULL, ' +
'title text, ' +
'"filePath" text NOT NULL, ' +
'size bigint NOT NULL, ' +
'"fileName" text NOT NULL, ' +
'"storageLocation" "enum_files_storageLocation" NOT NULL, ' +
'"createdAt" timestamp with time zone NOT NULL, ' +
'"updatedAt" timestamp with time zone NOT NULL, ' +
'"createdBy" character varying(128), ' +
'"updatedBy" character varying(128), ' +
'"submissionId" bigint, ' +
'"challengeId" bigint NOT NULL ' +
');'),
db.runSql.bind(db, 'ALTER TABLE ONLY files ADD CONSTRAINT files_pkey PRIMARY KEY (id);'),
'ALTER TABLE files ADD COLUMN storage_location enum_files_storage_location NOT NULL;'),

// participants table
db.createTable.bind(db, 'participants', {
'id': { type: 'int', primaryKey: true, autoIncrement: true, notNull: true },
'created_at': { type: 'timestamp', notNull: true },
'updated_at': { type: 'timestamp', notNull: true },
'created_by': { type: 'string', length: 128 },
'updated_by': { type: 'string', length: 128 },
'challenge_id': { type: 'bigint', notNull: true },
'user_id': { type: 'bigint', notNull: true }
}),
db.runSql.bind(db,
'CREATE TABLE participants ( ' +
'id bigserial NOT NULL, ' +
'role enum_participants_role NOT NULL, ' +
'"createdAt" timestamp with time zone NOT NULL, ' +
'"updatedAt" timestamp with time zone NOT NULL, ' +
'"createdBy" character varying(128), ' +
'"updatedBy" character varying(128), ' +
'"challengeId" bigint NOT NULL, ' +
'"userId" bigint NOT NULL ' +
');'),
db.runSql.bind(db, 'ALTER TABLE ONLY participants ADD CONSTRAINT participants_pkey PRIMARY KEY (id);'),
'ALTER TABLE files ADD COLUMN role enum_participants_role NOT NULL;'),

// submissions table
db.runSql.bind(db,
'CREATE TABLE submissions ( ' +
'id bigserial NOT NULL, ' +
'"createdAt" timestamp with time zone NOT NULL, ' +
'"updatedAt" timestamp with time zone NOT NULL, ' +
'"createdBy" character varying(128), ' +
'"updatedBy" character varying(128), ' +
'"challengeId" bigint NOT NULL, ' +
'"submitterId" bigint NOT NULL ' +
');'),
db.runSql.bind(db, 'ALTER TABLE ONLY submissions ADD CONSTRAINT submissions_pkey PRIMARY KEY (id);'),
db.createTable.bind(db, 'submissions', {
'id': { type: 'int', primaryKey: true, autoIncrement: true, notNull: true },
'created_at': { type: 'timestamp', notNull: true },
'updated_at': { type: 'timestamp', notNull: true },
'created_by': { type: 'string', length: 128 },
'updated_by': { type: 'string', length: 128 },
'challenge_id': { type: 'bigint', notNull: true },
'submitter_id': { type: 'bigint', notNull: true }
}),

// scorecards table
db.runSql.bind(db,
'CREATE TABLE scorecards ( ' +
'id bigserial NOT NULL, ' +
'"scoreSum" integer, ' +
'"scorePercent" double precision, ' +
'"scoreMax" double precision, ' +
'status enum_scorecards_status, ' +
'pay boolean, ' +
'place integer, ' +
'prize double precision, ' +
'"createdAt" timestamp with time zone NOT NULL, ' +
'"updatedAt" timestamp with time zone NOT NULL, ' +
'"createdBy" character varying(128), ' +
'"updatedBy" character varying(128), ' +
'"reviewerId" bigint NOT NULL, ' +
'"submissionId" bigint NOT NULL, ' +
'"challengeId" bigint NOT NULL ' +
');'),
db.runSql.bind(db, 'ALTER TABLE ONLY scorecards ADD CONSTRAINT scorecards_pkey PRIMARY KEY (id);'),
db.createTable.bind(db, 'scorecards', {
'id': { type: 'int', primaryKey: true, autoIncrement: true, notNull: true },
'score_sum': { type: 'int' },
'score_percent': { type: 'decimal' },
'score_max': { type: 'decimal' },
'pay': { type: 'boolean' },
'place': { type: 'int' },
'prize': { type: 'decimal' },
'created_at': { type: 'timestamp', notNull: true },
'updated_at': { type: 'timestamp', notNull: true },
'created_by': { type: 'string', length: 128 },
'updated_by': { type: 'string', length: 128 },
'reviewer_id': { type: 'bigint', notNull: true },
'submission_id': { type: 'bigint', notNull: true },
'challenge_id': { type: 'bigint', notNull: true }
}),
db.runSql.bind(db, 'ALTER TABLE scorecards ADD COLUMN status enum_scorecards_status;'),

// scorecard_items table
db.runSql.bind(db,
'CREATE TABLE scorecard_items ( ' +
'id bigserial NOT NULL, ' +
'"requirementId" integer, ' +
'score double precision, ' +
'comment text, ' +
'"createdAt" timestamp with time zone NOT NULL, ' +
'"updatedAt" timestamp with time zone NOT NULL, ' +
'"createdBy" character varying(128), ' +
'"updatedBy" character varying(128), ' +
'"scorecardId" bigint NOT NULL ' +
');'),
db.runSql.bind(db, 'ALTER TABLE ONLY scorecard_items ADD CONSTRAINT scorecard_items_pkey PRIMARY KEY (id);'),
db.createTable.bind(db, 'scorecard_items', {
'id': { type: 'int', primaryKey: true, autoIncrement: true, notNull: true },
'requirement_id': { type: 'int' },
'score': { type: 'decimal' },
'comment': { type: 'text' },
'created_at': { type: 'timestamp', notNull: true },
'updated_at': { type: 'timestamp', notNull: true },
'created_by': { type: 'string', length: 128 },
'updated_by': { type: 'string', length: 128 },
'scorecard_id': { type: 'bigint', notNull: true }
}),

// requirements table
db.runSql.bind(db,
'CREATE TABLE requirements ( ' +
'id bigserial NOT NULL, ' +
'"requirementText" text, ' +
'"challengeId" bigint NOT NULL REFERENCES challenges("id") ON UPDATE CASCADE ON DELETE SET NULL, ' +
'"createdAt" timestamp with time zone NOT NULL, ' +
'"updatedAt" timestamp with time zone NOT NULL ' +
');'),
db.createTable.bind(db, 'requirements', {
'id': { type: 'int', primaryKey: true, autoIncrement: true, notNull: true },
'requirement_text': { type: 'text' },
'created_at': { type: 'timestamp', notNull: true },
'updated_at': { type: 'timestamp', notNull: true }
}),
db.runSql.bind(db, 'ALTER TABLE requirements ADD COLUMN challenge_id bigint NOT NULL REFERENCES challenges("id") ON UPDATE CASCADE ON DELETE SET NULL;'),

// users table
db.runSql.bind(db,
'CREATE TABLE users ( ' +
'id bigserial NOT NULL, ' +
'name text, ' +
'email text, ' +
'"createdAt" timestamp with time zone NOT NULL, ' +
'"updatedAt" timestamp with time zone NOT NULL, ' +
'"createdBy" character varying(128), ' +
'"updatedBy" character varying(128) ' +
');'),
db.runSql.bind(db, 'ALTER TABLE ONLY users ADD CONSTRAINT users_pkey PRIMARY KEY (id);')

db.createTable.bind(db, 'users', {
'id': { type: 'int', primaryKey: true, autoIncrement: true, notNull: true },
'name': { type: 'text' },
'email': { type: 'text' },
'created_at': { type: 'timestamp', notNull: true },
'updated_at': { type: 'timestamp', notNull: true },
'created_by': { type: 'string', length: 128 },
'updated_by': { type: 'string', length: 128 }
}),
], callback);
};

Expand All @@ -146,4 +133,4 @@ exports.down = function (db, callback) {
db.dropTable.bind(db, 'files'),
db.dropTable.bind(db, 'challenges')
], callback);
};
};