From 9b981f410fdc8be0edee82604caf6de74171571e Mon Sep 17 00:00:00 2001 From: Adrian Rudolf Kral Date: Mon, 10 Nov 2014 20:08:31 +0100 Subject: [PATCH 1/8] Replaced raw SQL with DBMigration API where possible --- config/schema-migrations/20141010150000-enums.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/schema-migrations/20141010150000-enums.js b/config/schema-migrations/20141010150000-enums.js index 058b8e6..056bb0e 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); @@ -22,4 +22,4 @@ exports.down = function (db, callback) { 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 +}; From 6e97911eeed58a4f19afbb940b489cdc57aadad3 Mon Sep 17 00:00:00 2001 From: Adrian Rudolf Kral Date: Mon, 10 Nov 2014 20:08:59 +0100 Subject: [PATCH 2/8] CamelCase to underscored --- api/models/challenge.js | 1 + api/models/file.js | 1 + api/models/participant.js | 3 ++- api/models/requirement.js | 1 + api/models/scorecard.js | 1 + api/models/scorecardItem.js | 1 + api/models/submission.js | 3 ++- api/models/user.js | 1 + 8 files changed, 10 insertions(+), 2 deletions(-) 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); From e7da59c2105c0da8767046973d1d390bd3634b36 Mon Sep 17 00:00:00 2001 From: Adrian Rudolf Kral Date: Mon, 10 Nov 2014 20:09:30 +0100 Subject: [PATCH 3/8] Replaced raw SQL with DBMigration API where possible --- .../20141010160840-tables.js | 222 +++++++++--------- 1 file changed, 107 insertions(+), 115 deletions(-) diff --git a/config/schema-migrations/20141010160840-tables.js b/config/schema-migrations/20141010160840-tables.js index 34c634d..c79c25a 100644 --- a/config/schema-migrations/20141010160840-tables.js +++ b/config/schema-migrations/20141010160840-tables.js @@ -5,133 +5,125 @@ var type = dbm.dataType; exports.up = function (db, callback) { async.series([ // challenges table - 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);'), - + db.createTable('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 } + }, function(a) { + db.runSql.bind(db, + "ALTER TABLE challenges ADD COLUMN tags text[]," + + "ADD COLUMN prizes NUMERIC(11, 2)[]," + + "ADD COLUMN status enum_challenges_status NOT NULL;"); + }), + // files table - 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);'), + db.createTable('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} + }, function(a) { + db.runSql.bind(db, + 'ALTER TABLE files ADD COLUMN storage_location enum_files_storage_location NOT_NULL'); + }), // participants table - 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);'), + db.createTable('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 } + }, function(a) { + db.runSql.bind(db, + '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('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('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 } + }, function(a) { + 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('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('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 }, + }, function(a) { + 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('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 +138,4 @@ exports.down = function (db, callback) { db.dropTable.bind(db, 'files'), db.dropTable.bind(db, 'challenges') ], callback); -}; \ No newline at end of file +}; From 1e8d43ef0c250086a2b28b6cce69f36ab13e0576 Mon Sep 17 00:00:00 2001 From: Adrian Rudolf Kral Date: Mon, 10 Nov 2014 20:31:23 +0100 Subject: [PATCH 4/8] Fixed a small mistake and swagger.yaml --- api/swagger/swagger.yaml | 10 +++++----- config/schema-migrations/20141010150000-enums.js | 2 +- config/schema-migrations/20141010160840-tables.js | 14 +++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) 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 056bb0e..a8314c2 100644 --- a/config/schema-migrations/20141010150000-enums.js +++ b/config/schema-migrations/20141010150000-enums.js @@ -18,7 +18,7 @@ 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); diff --git a/config/schema-migrations/20141010160840-tables.js b/config/schema-migrations/20141010160840-tables.js index c79c25a..56cb9a3 100644 --- a/config/schema-migrations/20141010160840-tables.js +++ b/config/schema-migrations/20141010160840-tables.js @@ -30,7 +30,7 @@ exports.up = function (db, callback) { // files table db.createTable('files', { - 'id': { type: 'int', primaryKey: 'true', autoIncrement: true, notNull: true }, + 'id': { type: 'int', primaryKey: true, autoIncrement: true, notNull: true }, 'title': { type: 'text' }, 'file_path': { type: 'text', notNull: true }, 'size': { type: 'bigint', notNull: true }, @@ -48,7 +48,7 @@ exports.up = function (db, callback) { // participants table db.createTable('participants', { - 'id': { type: 'int', primaryKey: 'true', autoIncrement: true, notNull: true }, + '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 }, @@ -62,7 +62,7 @@ exports.up = function (db, callback) { // submissions table db.createTable('submissions', { - 'id': { type: 'int', primaryKey: 'true', autoIncrement: true, notNull: true }, + '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 }, @@ -73,7 +73,7 @@ exports.up = function (db, callback) { // scorecards table db.createTable('scorecards', { - 'id': { type: 'int', primaryKey: 'true', autoIncrement: true, notNull: true }, + 'id': { type: 'int', primaryKey: true, autoIncrement: true, notNull: true }, 'score_sum': { type: 'int' }, 'score_percent': { type: 'decimal' }, 'score_max': { type: 'decimal' }, @@ -93,7 +93,7 @@ exports.up = function (db, callback) { // scorecard_items table db.createTable('scorecard_items', { - 'id': { type: 'int', primaryKey: 'true', autoIncrement: true, notNull: true }, + 'id': { type: 'int', primaryKey: true, autoIncrement: true, notNull: true }, 'requirement_id': { type: 'int' }, 'score': { type: 'decimal' }, 'comment': { type: 'text' }, @@ -106,7 +106,7 @@ exports.up = function (db, callback) { // requirements table db.createTable('requirements', { - 'id': { type: 'int', primaryKey: 'true', autoIncrement: true, notNull: true }, + '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 }, @@ -116,7 +116,7 @@ exports.up = function (db, callback) { // users table db.createTable('users', { - 'id': { type: 'int', primaryKey: 'true', autoIncrement: true, notNull: true }, + 'id': { type: 'int', primaryKey: true, autoIncrement: true, notNull: true }, 'name': { type: 'text' }, 'email': { type: 'text' }, 'created_at': { type: 'timestamp', notNull: true }, From eed7a5c2eaed5beed55e95c3b1e18ad04bbe9d6a Mon Sep 17 00:00:00 2001 From: Adrian Rudolf Kral Date: Mon, 10 Nov 2014 21:01:55 +0100 Subject: [PATCH 5/8] Fixed missing semicolon --- config/schema-migrations/20141010160840-tables.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/schema-migrations/20141010160840-tables.js b/config/schema-migrations/20141010160840-tables.js index 56cb9a3..26b7eec 100644 --- a/config/schema-migrations/20141010160840-tables.js +++ b/config/schema-migrations/20141010160840-tables.js @@ -85,7 +85,7 @@ exports.up = function (db, callback) { 'created_by': { type: 'string', length: 128 }, 'updated_by': { type: 'string', length: 128 }, 'reviewer_id': { type: 'bigint', notNull: true }, - 'submission_id': { type: 'bigint', notNull: true } + 'submission_id': { type: 'bigint', notNull: true }, 'challenge_id': { type: 'bigint', notNull: true } }, function(a) { db.runSql.bind(db, 'ALTER TABLE scorecards ADD COLUMN status enum_scorecards_status'); @@ -109,7 +109,7 @@ exports.up = function (db, callback) { '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 }, + 'updated_at': { type: 'timestamp', notNull: true } }, function(a) { db.runSql.bind(db, 'ALTER TABLE requirements ADD COLUMN challenge_id bigint NOT NULL REFERENCES challenges("id") ON UPDATE CASCADE ON DELETE SET NULL;'); }), @@ -122,7 +122,7 @@ exports.up = function (db, callback) { 'created_at': { type: 'timestamp', notNull: true }, 'updated_at': { type: 'timestamp', notNull: true }, 'created_by': { type: 'string', length: 128 }, - 'updated_by': { type: 'string', length: 128 }, + 'updated_by': { type: 'string', length: 128 } }), ], callback); }; From d8402c4abf4ff97ec7f29df0691e7ca63e3c2619 Mon Sep 17 00:00:00 2001 From: Adrian Rudolf Kral Date: Mon, 10 Nov 2014 21:26:13 +0100 Subject: [PATCH 6/8] Fixed async usage(replaced function calls with functions) --- .../20141010160840-tables.js | 41 ++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/config/schema-migrations/20141010160840-tables.js b/config/schema-migrations/20141010160840-tables.js index 26b7eec..c083b49 100644 --- a/config/schema-migrations/20141010160840-tables.js +++ b/config/schema-migrations/20141010160840-tables.js @@ -5,7 +5,7 @@ var type = dbm.dataType; exports.up = function (db, callback) { async.series([ // challenges table - db.createTable('challenges', { + db.createTable.bind(db, 'challenges', { id: { type: 'int', primaryKey: true, autoIncrement: true, notNull: true }, reg_start_at: { type: 'timestamp' }, sub_end_at: { type: 'timestamp' }, @@ -21,15 +21,14 @@ exports.up = function (db, callback) { updated_at: { type: 'timestamp', notNull: true }, created_by: { type: 'string', length: 128 }, updated_by: { type: 'string', length: 128 } - }, function(a) { - db.runSql.bind(db, - "ALTER TABLE challenges ADD COLUMN tags text[]," + - "ADD COLUMN prizes NUMERIC(11, 2)[]," + - "ADD COLUMN status enum_challenges_status NOT NULL;"); }), + db.runSql.bind(db, + "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('files', { + db.createTable.bind(db, 'files', { 'id': { type: 'int', primaryKey: true, autoIncrement: true, notNull: true }, 'title': { type: 'text' }, 'file_path': { type: 'text', notNull: true }, @@ -41,13 +40,12 @@ exports.up = function (db, callback) { 'updated_by': { type: 'string', length: 128 }, 'submission_id': { type: 'bigint' }, 'challenge_id': { type: 'bigint', notNull: true} - }, function(a) { - db.runSql.bind(db, - 'ALTER TABLE files ADD COLUMN storage_location enum_files_storage_location NOT_NULL'); }), + db.runSql.bind(db, + 'ALTER TABLE files ADD COLUMN storage_location enum_files_storage_location NOT_NULL'), // participants table - db.createTable('participants', { + 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 }, @@ -55,13 +53,12 @@ exports.up = function (db, callback) { 'updated_by': { type: 'string', length: 128 }, 'challenge_id': { type: 'bigint', notNull: true }, 'user_id': { type: 'bigint', notNull: true } - }, function(a) { - db.runSql.bind(db, - 'ALTER TABLE files ADD COLUMN role enum_participants_role NOT_NULL'); }), + db.runSql.bind(db, + 'ALTER TABLE files ADD COLUMN role enum_participants_role NOT_NULL'), // submissions table - db.createTable('submissions', { + 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 }, @@ -72,7 +69,7 @@ exports.up = function (db, callback) { }), // scorecards table - db.createTable('scorecards', { + db.createTable.bind(db, 'scorecards', { 'id': { type: 'int', primaryKey: true, autoIncrement: true, notNull: true }, 'score_sum': { type: 'int' }, 'score_percent': { type: 'decimal' }, @@ -87,12 +84,11 @@ exports.up = function (db, callback) { 'reviewer_id': { type: 'bigint', notNull: true }, 'submission_id': { type: 'bigint', notNull: true }, 'challenge_id': { type: 'bigint', notNull: true } - }, function(a) { - db.runSql.bind(db, 'ALTER TABLE scorecards ADD COLUMN status enum_scorecards_status'); }), + db.runSql.bind(db, 'ALTER TABLE scorecards ADD COLUMN status enum_scorecards_status'), // scorecard_items table - db.createTable('scorecard_items', { + db.createTable.bind(db, 'scorecard_items', { 'id': { type: 'int', primaryKey: true, autoIncrement: true, notNull: true }, 'requirement_id': { type: 'int' }, 'score': { type: 'decimal' }, @@ -105,17 +101,16 @@ exports.up = function (db, callback) { }), // requirements table - db.createTable('requirements', { + 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 } - }, function(a) { - db.runSql.bind(db, 'ALTER TABLE requirements ADD COLUMN challenge_id bigint NOT NULL REFERENCES challenges("id") ON UPDATE CASCADE ON DELETE SET NULL;'); }), + 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.createTable('users', { + db.createTable.bind(db, 'users', { 'id': { type: 'int', primaryKey: true, autoIncrement: true, notNull: true }, 'name': { type: 'text' }, 'email': { type: 'text' }, From 96559b38258f8bfca3a2417d6aa93c25a26f4e03 Mon Sep 17 00:00:00 2001 From: Adrian Rudolf Kral Date: Mon, 10 Nov 2014 21:32:44 +0100 Subject: [PATCH 7/8] Added missing semicolons in SQL statements --- config/schema-migrations/20141010160840-tables.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/schema-migrations/20141010160840-tables.js b/config/schema-migrations/20141010160840-tables.js index c083b49..f61f11a 100644 --- a/config/schema-migrations/20141010160840-tables.js +++ b/config/schema-migrations/20141010160840-tables.js @@ -42,7 +42,7 @@ exports.up = function (db, callback) { 'challenge_id': { type: 'bigint', notNull: true} }), db.runSql.bind(db, - 'ALTER TABLE files ADD COLUMN storage_location enum_files_storage_location NOT_NULL'), + 'ALTER TABLE files ADD COLUMN storage_location enum_files_storage_location NOT_NULL;'), // participants table db.createTable.bind(db, 'participants', { @@ -55,7 +55,7 @@ exports.up = function (db, callback) { 'user_id': { type: 'bigint', notNull: true } }), db.runSql.bind(db, - 'ALTER TABLE files ADD COLUMN role enum_participants_role NOT_NULL'), + 'ALTER TABLE files ADD COLUMN role enum_participants_role NOT_NULL;'), // submissions table db.createTable.bind(db, 'submissions', { @@ -85,7 +85,7 @@ exports.up = function (db, callback) { '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'), + db.runSql.bind(db, 'ALTER TABLE scorecards ADD COLUMN status enum_scorecards_status;'), // scorecard_items table db.createTable.bind(db, 'scorecard_items', { From fc41de50c07a6ba9ca62f6055845f2dba77cbdd1 Mon Sep 17 00:00:00 2001 From: Adrian Rudolf Kral Date: Mon, 10 Nov 2014 21:35:52 +0100 Subject: [PATCH 8/8] Fixed "NOT_NULL" mistake --- config/schema-migrations/20141010160840-tables.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/schema-migrations/20141010160840-tables.js b/config/schema-migrations/20141010160840-tables.js index f61f11a..7e20ff9 100644 --- a/config/schema-migrations/20141010160840-tables.js +++ b/config/schema-migrations/20141010160840-tables.js @@ -42,7 +42,7 @@ exports.up = function (db, callback) { 'challenge_id': { type: 'bigint', notNull: true} }), db.runSql.bind(db, - 'ALTER TABLE files ADD COLUMN storage_location enum_files_storage_location NOT_NULL;'), + 'ALTER TABLE files ADD COLUMN storage_location enum_files_storage_location NOT NULL;'), // participants table db.createTable.bind(db, 'participants', { @@ -55,7 +55,7 @@ exports.up = function (db, callback) { 'user_id': { type: 'bigint', notNull: true } }), db.runSql.bind(db, - 'ALTER TABLE files ADD COLUMN role enum_participants_role NOT_NULL;'), + 'ALTER TABLE files ADD COLUMN role enum_participants_role NOT NULL;'), // submissions table db.createTable.bind(db, 'submissions', {