mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 18:31:57 +03:00
4604ba1587
no-issue * Handled send_email_when_published in Posts API This restores backwards compatibility of the Posts API allowing existing clients to continue to use the `send_email_when_published` flag. This change uses two edits, which is unfortunate. The reason being is that this is an API compatibility issue, not a model issue, so we shouldn't introduce code to the model layer to handle it. The visibility property of the model is used to determine how to fall back, and because it can be left out of the API request, and relies on a default in the settings, we require that the model decide on the `visibility` before we run our fallback logic (or we duplicate the `visibility` default at the cost of maintenance in the future) * Dropped send_email_when_published column from posts Since this column is not used any more, we can drop it from the table. We include an extra migration to repopulate the column in the event of a rollback * Updated importer to handle send_email_when_published Because we currently export this value from Ghost, we should correctly import it. This follows the same logic as the migrations for this value. * Included send_email_when_published in API response As our v3 API documentation includes `send_email_when_published` we must retain backward compatibility by calculating the property. * Fixed fields filter with send_email_when_published * Added safety checks to frame properties Some parts of the code pass a manually created "frame" which is missing lots of properties, so we check for the existence of all of them before using them. * Fixed 3.1 migration to include columnDefinition We require that migrations have all the information they need contained within them as they run in an unknown state of the codebase, which could be from the commit they are introduced, to any future commit. In this case the column definition is removed from the schema in 3.38 and the migration would fail when run in this version or later.
70 lines
3.1 KiB
JavaScript
70 lines
3.1 KiB
JavaScript
const should = require('should');
|
|
const _ = require('lodash');
|
|
const yaml = require('js-yaml');
|
|
const crypto = require('crypto');
|
|
const fs = require('fs-extra');
|
|
const path = require('path');
|
|
const {config} = require('../../../utils/configUtils');
|
|
const schema = require('../../../../core/server/data/schema');
|
|
const fixtures = require('../../../../core/server/data/schema/fixtures');
|
|
const frontendSettings = require('../../../../core/frontend/services/settings');
|
|
const validateFrontendSettings = require('../../../../core/frontend/services/settings/validate');
|
|
const defaultSettings = require('../../../../core/server/data/schema/default-settings');
|
|
|
|
/**
|
|
* @NOTE
|
|
*
|
|
* If this test fails for you, you have modified one of:
|
|
* - the database schema
|
|
* - fixtures
|
|
* - default settings
|
|
* - routes.yaml
|
|
*
|
|
* 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.
|
|
* You have to add a migration script if you've added new settings to populate group/flags column.
|
|
*/
|
|
describe('DB version integrity', function () {
|
|
// Only these variables should need updating
|
|
const currentSchemaHash = '102b04bbd38cd2451fbf0957ffc35b30';
|
|
const currentFixturesHash = 'd46d696c94d03e41a5903500547fea77';
|
|
const currentSettingsHash = '229360069a9c77a945727a3c5869c3c6';
|
|
const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';
|
|
|
|
// 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 () {
|
|
const routesPath = path.join(config.get('paths').defaultSettings, 'default-routes.yaml');
|
|
const defaultRoutes = validateFrontendSettings(yaml.safeLoad(fs.readFileSync(routesPath, 'utf-8')));
|
|
|
|
const tablesNoValidation = _.cloneDeep(schema.tables);
|
|
let schemaHash;
|
|
let fixturesHash;
|
|
let settingsHash;
|
|
let routesHash;
|
|
|
|
_.each(tablesNoValidation, function (table) {
|
|
return _.each(table, function (column, name) {
|
|
table[name] = _.omit(column, 'validations');
|
|
});
|
|
});
|
|
|
|
schemaHash = crypto.createHash('md5').update(JSON.stringify(tablesNoValidation), 'binary').digest('hex');
|
|
fixturesHash = crypto.createHash('md5').update(JSON.stringify(fixtures), 'binary').digest('hex');
|
|
settingsHash = crypto.createHash('md5').update(JSON.stringify(defaultSettings), 'binary').digest('hex');
|
|
routesHash = crypto.createHash('md5').update(JSON.stringify(defaultRoutes), 'binary').digest('hex');
|
|
|
|
schemaHash.should.eql(currentSchemaHash);
|
|
fixturesHash.should.eql(currentFixturesHash);
|
|
settingsHash.should.eql(currentSettingsHash);
|
|
routesHash.should.eql(currentRoutesHash);
|
|
routesHash.should.eql(frontendSettings.getDefaulHash('routes'));
|
|
});
|
|
});
|