mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 13:54:35 +03:00
Added new portal_products
setting (#13055)
refs https://github.com/TryGhost/Team/issues/768 - `portal_products` stores list of products available in Portal - adds new `portal_products` setting to default settings - adds migration to populate `portal_products` with current product so its available by default - update tests
This commit is contained in:
parent
587f6806df
commit
8f104f67b1
@ -0,0 +1,69 @@
|
||||
const ObjectID = require('bson-objectid');
|
||||
const {createTransactionalMigration} = require('../../utils');
|
||||
const logging = require('@tryghost/logging');
|
||||
|
||||
const MIGRATION_USER = 1;
|
||||
|
||||
module.exports = createTransactionalMigration(
|
||||
async function up(knex) {
|
||||
const products = await knex
|
||||
.select('id')
|
||||
.from('products');
|
||||
|
||||
if (products.length === 0) {
|
||||
logging.warn(`Skipping adding default product to portal_products, no default product exists`);
|
||||
return;
|
||||
}
|
||||
|
||||
const defaultProduct = products[0];
|
||||
const portalProductsValue = [defaultProduct.id];
|
||||
|
||||
const portalProductsSetting = await knex('settings')
|
||||
.where('key', 'portal_products')
|
||||
.select('value')
|
||||
.first();
|
||||
|
||||
if (!portalProductsSetting) {
|
||||
logging.info(`Adding "portal_products" record to "settings" table with product - ${defaultProduct.id}`);
|
||||
|
||||
const now = knex.raw('CURRENT_TIMESTAMP');
|
||||
|
||||
await knex('settings')
|
||||
.insert({
|
||||
id: ObjectID().toHexString(),
|
||||
key: 'portal_products',
|
||||
value: JSON.stringify(portalProductsValue),
|
||||
group: 'portal',
|
||||
type: 'array',
|
||||
created_at: now,
|
||||
created_by: MIGRATION_USER,
|
||||
updated_at: now,
|
||||
updated_by: MIGRATION_USER
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
logging.info(`Setting portal_products setting to have product - ${defaultProduct.id}`);
|
||||
|
||||
await knex('settings')
|
||||
.where('key', 'portal_products')
|
||||
.update({value: JSON.stringify(portalProductsValue)});
|
||||
},
|
||||
async function down(knex) {
|
||||
const portalProductSetting = await knex('settings')
|
||||
.where('key', 'portal_products')
|
||||
.select('value')
|
||||
.first();
|
||||
|
||||
if (!portalProductSetting) {
|
||||
logging.info('Skipping revert of portal_products setting, setting does not exist');
|
||||
return;
|
||||
}
|
||||
|
||||
logging.info(`Reverting portal_products setting to empty array`);
|
||||
|
||||
await knex('settings')
|
||||
.where('key', 'portal_products')
|
||||
.update({value: JSON.stringify([])});
|
||||
}
|
||||
);
|
@ -343,6 +343,10 @@
|
||||
"defaultValue": "[\"free\"]",
|
||||
"type": "array"
|
||||
},
|
||||
"portal_products": {
|
||||
"defaultValue": "[]",
|
||||
"type": "array"
|
||||
},
|
||||
"portal_button_style": {
|
||||
"defaultValue": "icon-and-text",
|
||||
"validations": {
|
||||
|
@ -255,6 +255,11 @@ const defaultSettingsKeyTypes = [
|
||||
type: 'array',
|
||||
group: 'portal'
|
||||
},
|
||||
{
|
||||
key: 'portal_products',
|
||||
type: 'array',
|
||||
group: 'portal'
|
||||
},
|
||||
{
|
||||
key: 'portal_button_style',
|
||||
type: 'string',
|
||||
|
@ -54,6 +54,7 @@ const defaultSettingsKeyTypes = [
|
||||
{key: 'portal_name', type: 'portal'},
|
||||
{key: 'portal_button', type: 'portal'},
|
||||
{key: 'portal_plans', type: 'portal'},
|
||||
{key: 'portal_products', type: 'portal'},
|
||||
{key: 'portal_button_style', type: 'portal'},
|
||||
{key: 'portal_button_icon', type: 'portal'},
|
||||
{key: 'portal_button_signup_text', type: 'portal'},
|
||||
|
@ -57,6 +57,7 @@ const defaultSettingsKeyTypes = [
|
||||
{key: 'portal_name', type: 'portal'},
|
||||
{key: 'portal_button', type: 'portal'},
|
||||
{key: 'portal_plans', type: 'portal'},
|
||||
{key: 'portal_products', type: 'portal'},
|
||||
{key: 'portal_button_style', type: 'portal'},
|
||||
{key: 'portal_button_icon', type: 'portal'},
|
||||
{key: 'portal_button_signup_text', type: 'portal'},
|
||||
|
@ -191,7 +191,7 @@ describe('Exporter', function () {
|
||||
|
||||
// NOTE: if default settings changed either modify the settings keys blocklist or increase allowedKeysLength
|
||||
// This is a reminder to think about the importer/exporter scenarios ;)
|
||||
const allowedKeysLength = 83;
|
||||
const allowedKeysLength = 84;
|
||||
totalKeysLength.should.eql(SETTING_KEYS_BLOCKLIST.length + allowedKeysLength);
|
||||
});
|
||||
});
|
||||
|
@ -34,7 +34,7 @@ describe('DB version integrity', function () {
|
||||
// Only these variables should need updating
|
||||
const currentSchemaHash = 'ef13a18aee78222086ca864c16bde696';
|
||||
const currentFixturesHash = '8671672598d2a62e53418c4b91aa79a3';
|
||||
const currentSettingsHash = 'fec0d2f71557a9bd2ff5ff8b423e11be';
|
||||
const currentSettingsHash = '9986400eb68ccb55173b181c2be4f94a';
|
||||
const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';
|
||||
|
||||
// If this test is failing, then it is likely a change has been made that requires a DB version bump,
|
||||
|
Loading…
Reference in New Issue
Block a user