2020-04-29 16:44:27 +01:00
|
|
|
const should = require('should');
|
|
|
|
const _ = require('lodash');
|
|
|
|
const crypto = require('crypto');
|
|
|
|
const schema = require('../../../../core/server/data/schema');
|
|
|
|
const fixtures = require('../../../../core/server/data/schema/fixtures');
|
2020-07-10 15:52:07 +05:30
|
|
|
const defaultSettings = require('../../../../core/server/data/schema/default-settings');
|
2017-02-14 13:41:28 +01:00
|
|
|
|
2017-12-11 12:35:27 +01:00
|
|
|
/**
|
|
|
|
* @NOTE
|
|
|
|
*
|
2020-07-10 15:52:07 +05:30
|
|
|
* If this test fails for you, you have modified the database schema or fixtures or default settings.
|
2017-12-11 12:35:27 +01:00
|
|
|
* When you make a change, please test that:
|
|
|
|
*
|
|
|
|
* 1. A new blog get's installed and the database looks correct and complete.
|
|
|
|
* 2. A blog get's updated from a lower Ghost version and the database looks correct and complete.
|
|
|
|
*
|
|
|
|
* Typical cases:
|
|
|
|
* You have to add a migration script if you've added/modified permissions.
|
|
|
|
* You have to add a migration script if you've add a new table.
|
2020-07-10 15:52:07 +05:30
|
|
|
* You have to add a migration script if you've added new settings to populate group/flags column.
|
2017-12-11 12:35:27 +01:00
|
|
|
*/
|
2017-01-25 14:47:49 +01:00
|
|
|
describe('DB version integrity', function () {
|
2016-03-21 12:44:23 +00:00
|
|
|
// Only these variables should need updating
|
2020-07-06 12:12:30 +02:00
|
|
|
const currentSchemaHash = '134c9de4e59b31ec6b73f03638a01396';
|
2020-07-06 19:25:08 +01:00
|
|
|
const currentFixturesHash = '3d942c46e8487c4aee1e9ac898ed29ca';
|
2020-07-10 15:19:45 +02:00
|
|
|
const currentSettingsHash = 'a4ac78d3810175428b4833645231d6d5';
|
2016-03-21 12:44:23 +00:00
|
|
|
|
|
|
|
// If this test is failing, then it is likely a change has been made that requires a DB version bump,
|
|
|
|
// and the values above will need updating as confirmation
|
|
|
|
it('should not change without fixing this test', function () {
|
2020-04-29 16:44:27 +01:00
|
|
|
const tablesNoValidation = _.cloneDeep(schema.tables);
|
|
|
|
let schemaHash;
|
|
|
|
let fixturesHash;
|
2020-07-10 15:52:07 +05:30
|
|
|
let settingsHash;
|
2016-03-21 12:44:23 +00:00
|
|
|
|
|
|
|
_.each(tablesNoValidation, function (table) {
|
|
|
|
return _.each(table, function (column, name) {
|
|
|
|
table[name] = _.omit(column, 'validations');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-04-05 20:16:28 +01:00
|
|
|
schemaHash = crypto.createHash('md5').update(JSON.stringify(tablesNoValidation), 'binary').digest('hex');
|
|
|
|
fixturesHash = crypto.createHash('md5').update(JSON.stringify(fixtures), 'binary').digest('hex');
|
2020-07-10 15:52:07 +05:30
|
|
|
settingsHash = crypto.createHash('md5').update(JSON.stringify(defaultSettings), 'binary').digest('hex');
|
2016-03-21 12:44:23 +00:00
|
|
|
|
|
|
|
schemaHash.should.eql(currentSchemaHash);
|
|
|
|
fixturesHash.should.eql(currentFixturesHash);
|
2020-07-10 15:52:07 +05:30
|
|
|
settingsHash.should.eql(currentSettingsHash);
|
2016-03-21 12:44:23 +00:00
|
|
|
});
|
|
|
|
});
|