diff --git a/api/models/challenge.js b/api/models/challenge.js index 09dd107..392e877 100644 --- a/api/models/challenge.js +++ b/api/models/challenge.js @@ -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); diff --git a/api/models/file.js b/api/models/file.js index 8405282..334c0a8 100644 --- a/api/models/file.js +++ b/api/models/file.js @@ -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'}); diff --git a/api/models/participant.js b/api/models/participant.js index e79b990..40c15b3 100644 --- a/api/models/participant.js +++ b/api/models/participant.js @@ -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'}); @@ -53,4 +54,4 @@ module.exports = function(sequelize, DataTypes) { return Participant; -}; \ No newline at end of file +}; diff --git a/api/models/requirement.js b/api/models/requirement.js index 472f445..590092f 100644 --- a/api/models/requirement.js +++ b/api/models/requirement.js @@ -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); diff --git a/api/models/scorecard.js b/api/models/scorecard.js index e1eb587..92dec3f 100644 --- a/api/models/scorecard.js +++ b/api/models/scorecard.js @@ -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'}); diff --git a/api/models/scorecardItem.js b/api/models/scorecardItem.js index 1ccfe45..740dbd0 100644 --- a/api/models/scorecardItem.js +++ b/api/models/scorecardItem.js @@ -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'}); diff --git a/api/models/submission.js b/api/models/submission.js index 05cb2f5..f50f350 100644 --- a/api/models/submission.js +++ b/api/models/submission.js @@ -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); @@ -48,4 +49,4 @@ module.exports = function(sequelize, DataTypes) { return Submission; -}; \ No newline at end of file +}; diff --git a/api/models/user.js b/api/models/user.js index 27b9d2b..3e809c0 100644 --- a/api/models/user.js +++ b/api/models/user.js @@ -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); diff --git a/api/swagger/swagger.yaml b/api/swagger/swagger.yaml index 0542236..de7e1e3 100644 --- a/api/swagger/swagger.yaml +++ b/api/swagger/swagger.yaml @@ -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 @@ -1941,4 +1941,4 @@ definitions: description: The http status code content: type: string - description: The error message \ No newline at end of file + description: The error message diff --git a/config/schema-migrations/20141010150000-enums.js b/config/schema-migrations/20141010150000-enums.js index 058b8e6..a8314c2 100644 --- a/config/schema-migrations/20141010150000-enums.js +++ b/config/schema-migrations/20141010150000-enums.js @@ -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); @@ -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); -}; \ No newline at end of file +}; diff --git a/config/schema-migrations/20141010160840-tables.js b/config/schema-migrations/20141010160840-tables.js index 34c634d..7e20ff9 100644 --- a/config/schema-migrations/20141010160840-tables.js +++ b/config/schema-migrations/20141010160840-tables.js @@ -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); }; @@ -146,4 +133,4 @@ exports.down = function (db, callback) { db.dropTable.bind(db, 'files'), db.dropTable.bind(db, 'challenges') ], callback); -}; \ No newline at end of file +};