Skip to content

Commit

Permalink
Added mobiledoc_revisions schema, migration script and updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhgrg authored and kirrg001 committed Oct 2, 2018
1 parent 96488af commit 91f8e03
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
@@ -0,0 +1,35 @@
const common = require('../../../../lib/common');
const commands = require('../../../schema').commands;
const table = 'mobiledoc_revisions';
const message1 = 'Adding table: ' + table;
const message2 = 'Dropping table: ' + table;

module.exports.up = (options) => {
const connection = options.connection;

return connection.schema.hasTable(table)
.then(function (exists) {
if (exists) {
common.logging.warn(message1);
return;
}

common.logging.info(message1);
return commands.createTable(table, connection);
});
};

module.exports.down = (options) => {
const connection = options.connection;

return connection.schema.hasTable(table)
.then(function (exists) {
if (!exists) {
common.logging.warn(message2);
return;
}

common.logging.info(message2);
return commands.deleteTable(table, connection);
});
};
7 changes: 7 additions & 0 deletions core/server/data/schema/schema.js
Expand Up @@ -344,5 +344,12 @@ module.exports = {
created_by: {type: 'string', maxlength: 24, nullable: false},
updated_at: {type: 'dateTime', nullable: true},
updated_by: {type: 'string', maxlength: 24, nullable: true}
},
mobiledoc_revisions: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
post_id: {type: 'string', maxlength: 24, nullable: false, index: true},
mobiledoc: {type: 'text', maxlength: 1000000000, fieldtype: 'long', nullable: true},
created_at_ts: {type: 'bigInteger', nullable: false},
created_at: {type: 'dateTime', nullable: false}
}
};
4 changes: 2 additions & 2 deletions core/test/functional/routes/api/db_spec.js
Expand Up @@ -72,7 +72,7 @@ describe('DB API', function () {
var jsonResponse = res.body;
should.exist(jsonResponse.db);
jsonResponse.db.should.have.length(1);
Object.keys(jsonResponse.db[0].data).length.should.eql(24);
Object.keys(jsonResponse.db[0].data).length.should.eql(25);
done();
});
});
Expand All @@ -90,7 +90,7 @@ describe('DB API', function () {
const jsonResponse = res.body;
should.exist(jsonResponse.db);
jsonResponse.db.should.have.length(1);
Object.keys(jsonResponse.db[0].data).length.should.eql(26);
Object.keys(jsonResponse.db[0].data).length.should.eql(27);
done();
});
});
Expand Down
2 changes: 1 addition & 1 deletion core/test/unit/data/schema/integrity_spec.js
Expand Up @@ -19,7 +19,7 @@ var should = require('should'),
*/
describe('DB version integrity', function () {
// Only these variables should need updating
const currentSchemaHash = '1834b95684f1916f79e51bab8d6eac8f';
const currentSchemaHash = '1e26cc4d159e43a0607d72d1e44050d1';
const currentFixturesHash = '20292edf9fd692cbd6485267a2ac8e75';

// If this test is failing, then it is likely a change has been made that requires a DB version bump,
Expand Down

1 comment on commit 91f8e03

@kirrg001
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reference was not added.

This commit refs #9927.

Please sign in to comment.