2020-04-29 18:44:27 +03:00
|
|
|
const should = require('should');
|
|
|
|
const _ = require('lodash');
|
2020-09-09 15:28:12 +03:00
|
|
|
const yaml = require('js-yaml');
|
2020-04-29 18:44:27 +03:00
|
|
|
const crypto = require('crypto');
|
2020-09-09 15:28:12 +03:00
|
|
|
const fs = require('fs-extra');
|
|
|
|
const path = require('path');
|
|
|
|
const {config} = require('../../../utils/configUtils');
|
2020-04-29 18:44:27 +03:00
|
|
|
const schema = require('../../../../core/server/data/schema');
|
|
|
|
const fixtures = require('../../../../core/server/data/schema/fixtures');
|
2020-09-09 15:28:12 +03:00
|
|
|
const frontendSettings = require('../../../../core/frontend/services/settings');
|
|
|
|
const validateFrontendSettings = require('../../../../core/frontend/services/settings/validate');
|
2020-07-10 13:22:07 +03:00
|
|
|
const defaultSettings = require('../../../../core/server/data/schema/default-settings');
|
2017-02-14 15:41:28 +03:00
|
|
|
|
2017-12-11 14:35:27 +03:00
|
|
|
/**
|
|
|
|
* @NOTE
|
|
|
|
*
|
2020-09-09 15:28:12 +03:00
|
|
|
* If this test fails for you, you have modified one of:
|
|
|
|
* - the database schema
|
|
|
|
* - fixtures
|
|
|
|
* - default settings
|
|
|
|
* - routes.yaml
|
|
|
|
*
|
2017-12-11 14:35:27 +03: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 13:22:07 +03:00
|
|
|
* You have to add a migration script if you've added new settings to populate group/flags column.
|
2017-12-11 14:35:27 +03:00
|
|
|
*/
|
2017-01-25 16:47:49 +03:00
|
|
|
describe('DB version integrity', function () {
|
2016-03-21 15:44:23 +03:00
|
|
|
// Only these variables should need updating
|
2020-08-05 14:20:30 +03:00
|
|
|
const currentSchemaHash = '42a966364eb4b5851e807133374821da';
|
2020-08-18 11:47:56 +03:00
|
|
|
const currentFixturesHash = '29148c40dfaf4f828c5fca95666f6545';
|
2020-09-07 12:54:55 +03:00
|
|
|
const currentSettingsHash = 'c8daa2c9632bb75f9d60655de09ae3bd';
|
2020-09-09 15:28:12 +03:00
|
|
|
const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';
|
2016-03-21 15:44:23 +03: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-09-10 03:57:03 +03:00
|
|
|
const routesPath = path.join(config.get('paths').defaultSettings, 'default-routes.yaml');
|
2020-09-09 15:28:12 +03:00
|
|
|
const defaultRoutes = validateFrontendSettings(yaml.safeLoad(fs.readFileSync(routesPath, 'utf-8')));
|
|
|
|
|
2020-04-29 18:44:27 +03:00
|
|
|
const tablesNoValidation = _.cloneDeep(schema.tables);
|
|
|
|
let schemaHash;
|
|
|
|
let fixturesHash;
|
2020-07-10 13:22:07 +03:00
|
|
|
let settingsHash;
|
2020-09-09 15:28:12 +03:00
|
|
|
let routesHash;
|
2016-03-21 15:44:23 +03:00
|
|
|
|
|
|
|
_.each(tablesNoValidation, function (table) {
|
|
|
|
return _.each(table, function (column, name) {
|
|
|
|
table[name] = _.omit(column, 'validations');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-04-05 22:16:28 +03: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 13:22:07 +03:00
|
|
|
settingsHash = crypto.createHash('md5').update(JSON.stringify(defaultSettings), 'binary').digest('hex');
|
2020-09-09 15:28:12 +03:00
|
|
|
routesHash = crypto.createHash('md5').update(JSON.stringify(defaultRoutes), 'binary').digest('hex');
|
2016-03-21 15:44:23 +03:00
|
|
|
|
|
|
|
schemaHash.should.eql(currentSchemaHash);
|
|
|
|
fixturesHash.should.eql(currentFixturesHash);
|
2020-07-10 13:22:07 +03:00
|
|
|
settingsHash.should.eql(currentSettingsHash);
|
2020-09-09 15:28:12 +03:00
|
|
|
routesHash.should.eql(currentRoutesHash);
|
|
|
|
routesHash.should.eql(frontendSettings.getDefaulHash('routes'));
|
2016-03-21 15:44:23 +03:00
|
|
|
});
|
|
|
|
});
|