0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Added pivot table to store tiers on post (#14038)

refs https://github.com/TryGhost/Team/issues/1071

We used `posts.visibility` originally to store visibility as `free|paid` with a character limit of 50. This same field was repurposed to store an NQL filter when member tiers is enabled. The NQL filter uses the slug of the tier name, which can easily create a filter longer than 50 characters, adding an unwanted limitation on number of tiers that can be added to post's visibility.
Going forward, we'd like to store the visibility of posts for tiers in a separate pivot table and instead store the value of `visibility` as `tiers` when restricting post access to specific tiers. This change -

- adds a new pivot table fixture for storing relation between posts and tiers
- adds a migration for creating the new table
- updates tests
This commit is contained in:
Rishabh Garg 2022-01-31 15:33:58 +05:30 committed by GitHub
parent 79609632b1
commit eeafc8603b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 1 deletions

View file

@ -10,6 +10,7 @@ const BACKUP_TABLES = [
'members',
'members_labels',
'members_products',
'posts_products',
'members_stripe_customers',
'members_stripe_customers_subscriptions',
'migrations',

View file

@ -0,0 +1,8 @@
const {addTable} = require('../../utils');
module.exports = addTable('posts_products', {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
post_id: {type: 'string', maxlength: 24, nullable: false, references: 'posts.id', cascadeDelete: true},
product_id: {type: 'string', maxlength: 24, nullable: false, references: 'products.id', cascadeDelete: true},
sort_order: {type: 'integer', nullable: false, unsigned: true, defaultTo: 0}
});

View file

@ -424,6 +424,12 @@ module.exports = {
product_id: {type: 'string', maxlength: 24, nullable: false, references: 'products.id', cascadeDelete: true},
sort_order: {type: 'integer', nullable: false, unsigned: true, defaultTo: 0}
},
posts_products: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
post_id: {type: 'string', maxlength: 24, nullable: false, references: 'posts.id', cascadeDelete: true},
product_id: {type: 'string', maxlength: 24, nullable: false, references: 'products.id', cascadeDelete: true},
sort_order: {type: 'integer', nullable: false, unsigned: true, defaultTo: 0}
},
members_payment_events: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
member_id: {type: 'string', maxlength: 24, nullable: false, references: 'members.id', cascadeDelete: true},

View file

@ -55,6 +55,7 @@ describe('Exporter', function () {
'permissions_roles',
'permissions_users',
'posts',
'posts_products',
'posts_authors',
'posts_meta',
'posts_tags',

View file

@ -35,7 +35,7 @@ const validateRouteSettings = require('../../../../../core/server/services/route
*/
describe('DB version integrity', function () {
// Only these variables should need updating
const currentSchemaHash = '690caeeb4b3b52591a204704aa15dec9';
const currentSchemaHash = '95bef616ba2bf7b91a99c627bbc591a3';
const currentFixturesHash = 'beb040c0376a492c2a44767fdd825a3e';
const currentSettingsHash = 'd73b63e33153c9256bca42ebfd376779';
const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';