2020-04-29 16:44:27 +01:00
|
|
|
const should = require('should');
|
|
|
|
const _ = require('lodash');
|
2020-09-10 00:28:12 +12:00
|
|
|
const yaml = require('js-yaml');
|
2020-04-29 16:44:27 +01:00
|
|
|
const crypto = require('crypto');
|
2020-09-10 00:28:12 +12:00
|
|
|
const fs = require('fs-extra');
|
|
|
|
const path = require('path');
|
2021-10-06 11:12:21 +01:00
|
|
|
const {config} = require('../../../../utils/configUtils');
|
2021-10-20 19:26:03 +01:00
|
|
|
const schema = require('../../../../../core/server/data/schema/schema');
|
|
|
|
const fixtures = require('../../../../../core/server/data/schema/fixtures/fixtures.json');
|
2022-02-18 09:58:06 +07:00
|
|
|
const defaultSettings = require('../../../../../core/server/data/schema/default-settings/default-settings.json');
|
2021-10-20 19:26:03 +01:00
|
|
|
|
|
|
|
// Routes are yaml so we can require the file directly
|
2021-10-06 11:12:21 +01:00
|
|
|
const routeSettings = require('../../../../../core/server/services/route-settings');
|
2021-11-23 12:38:49 +04:00
|
|
|
routeSettings.init();
|
2021-10-06 11:12:21 +01:00
|
|
|
const validateRouteSettings = require('../../../../../core/server/services/route-settings/validate');
|
2017-02-14 13:41:28 +01:00
|
|
|
|
2017-12-11 12:35:27 +01:00
|
|
|
/**
|
|
|
|
* @NOTE
|
|
|
|
*
|
2020-09-10 00:28:12 +12:00
|
|
|
* If this test fails for you, you have modified one of:
|
|
|
|
* - the database schema
|
|
|
|
* - fixtures
|
|
|
|
* - default settings
|
|
|
|
* - routes.yaml
|
|
|
|
*
|
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
|
2022-03-08 17:51:36 +01:00
|
|
|
const currentSchemaHash = 'b7867be4de694b4592d748c0367064b5';
|
2022-03-16 16:46:26 +05:30
|
|
|
const currentFixturesHash = 'f4dd2a454e1999b6d149cc26ae52ced4';
|
2022-03-10 17:41:46 +00:00
|
|
|
const currentSettingsHash = '71fa38d0c805c18ceebe0fda80886230';
|
2020-09-10 00:28:12 +12:00
|
|
|
const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';
|
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 () {
|
2022-02-18 09:17:10 +07:00
|
|
|
const routesPath = path.join(config.get('paths').defaultRouteSettings, 'default-routes.yaml');
|
2021-09-27 14:38:48 +02:00
|
|
|
const defaultRoutes = validateRouteSettings(yaml.load(fs.readFileSync(routesPath, 'utf-8')));
|
2020-09-10 00:28:12 +12:00
|
|
|
|
2021-10-20 19:26:03 +01:00
|
|
|
const tablesNoValidation = _.cloneDeep(schema);
|
2020-04-29 16:44:27 +01:00
|
|
|
let schemaHash;
|
|
|
|
let fixturesHash;
|
2020-07-10 15:52:07 +05:30
|
|
|
let settingsHash;
|
2020-09-10 00:28:12 +12:00
|
|
|
let routesHash;
|
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');
|
2020-09-10 00:28:12 +12:00
|
|
|
routesHash = crypto.createHash('md5').update(JSON.stringify(defaultRoutes), '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);
|
2020-09-10 00:28:12 +12:00
|
|
|
routesHash.should.eql(currentRoutesHash);
|
2021-09-27 16:34:15 +02:00
|
|
|
routesHash.should.eql(routeSettings.getDefaultHash());
|
2016-03-21 12:44:23 +00:00
|
|
|
});
|
|
|
|
});
|