From 89e9e4a2b8b982b330b28f71b4f9f6a26b197aa0 Mon Sep 17 00:00:00 2001 From: Sag Date: Wed, 30 Aug 2023 10:33:49 +0200 Subject: [PATCH] Added Recommendations table (#17862) closes https://github.com/TryGhost/Product/issues/3775 - Recommendations tech spec: https://www.notion.so/ghost/Recommentions-Tech-Spec-598f09e4109f4eef8d9e32db7245a90c?pvs=4#d59dd64cf40144bc944319b65436a730 --- .../core/server/data/exporter/table-lists.js | 3 ++- ...8-29-11-39-10-add-recommendations-table.js | 18 +++++++++++++ ghost/core/core/server/data/schema/schema.js | 12 +++++++++ .../integration/exporter/exporter.test.js | 27 ++++++++++--------- .../unit/server/data/schema/integrity.test.js | 2 +- 5 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 ghost/core/core/server/data/migrations/versions/5.61/2023-08-29-11-39-10-add-recommendations-table.js diff --git a/ghost/core/core/server/data/exporter/table-lists.js b/ghost/core/core/server/data/exporter/table-lists.js index 87c372492b..c38dd07828 100644 --- a/ghost/core/core/server/data/exporter/table-lists.js +++ b/ghost/core/core/server/data/exporter/table-lists.js @@ -50,7 +50,8 @@ const BACKUP_TABLES = [ 'email_spam_complaint_events', 'milestones', 'collections', - 'collections_posts' + 'collections_posts', + 'recommendations' ]; // NOTE: exposing only tables which are going to be included in a "default" export file diff --git a/ghost/core/core/server/data/migrations/versions/5.61/2023-08-29-11-39-10-add-recommendations-table.js b/ghost/core/core/server/data/migrations/versions/5.61/2023-08-29-11-39-10-add-recommendations-table.js new file mode 100644 index 0000000000..941c95bdb0 --- /dev/null +++ b/ghost/core/core/server/data/migrations/versions/5.61/2023-08-29-11-39-10-add-recommendations-table.js @@ -0,0 +1,18 @@ +const {addTable} = require('../../utils'); + +module.exports = addTable('recommendations', { + id: {type: 'string', maxlength: 24, nullable: false, primary: true}, + + url: {type: 'string', maxlength: 2000, nullable: false}, + title: {type: 'string', maxlength: 2000, nullable: false}, + + excerpt: {type: 'string', maxlength: 2000, nullable: true}, + featured_image: {type: 'string', maxlength: 2000, nullable: true}, + favicon: {type: 'string', maxlength: 2000, nullable: true}, + + reason: {type: 'string', maxlength: 2000, nullable: true}, + one_click_subscribe: {type: 'boolean', nullable: false, defaultTo: false}, + + created_at: {type: 'dateTime', nullable: false}, + updated_at: {type: 'dateTime', nullable: true} +}); diff --git a/ghost/core/core/server/data/schema/schema.js b/ghost/core/core/server/data/schema/schema.js index 050470d180..b00283f6e8 100644 --- a/ghost/core/core/server/data/schema/schema.js +++ b/ghost/core/core/server/data/schema/schema.js @@ -1067,5 +1067,17 @@ module.exports = { collection_id: {type: 'string', maxlength: 24, nullable: false, references: 'collections.id', cascadeDelete: true}, post_id: {type: 'string', maxlength: 24, nullable: false, references: 'posts.id', cascadeDelete: true}, sort_order: {type: 'integer', nullable: false, unsigned: true, defaultTo: 0} + }, + recommendations: { + id: {type: 'string', maxlength: 24, nullable: false, primary: true}, + url: {type: 'string', maxlength: 2000, nullable: false}, + title: {type: 'string', maxlength: 2000, nullable: false}, + excerpt: {type: 'string', maxlength: 2000, nullable: true}, + featured_image: {type: 'string', maxlength: 2000, nullable: true}, + favicon: {type: 'string', maxlength: 2000, nullable: true}, + reason: {type: 'string', maxlength: 2000, nullable: true}, + one_click_subscribe: {type: 'boolean', nullable: false, defaultTo: false}, + created_at: {type: 'dateTime', nullable: false}, + updated_at: {type: 'dateTime', nullable: true} } }; diff --git a/ghost/core/test/integration/exporter/exporter.test.js b/ghost/core/test/integration/exporter/exporter.test.js index 5a30f2460e..aafbadf194 100644 --- a/ghost/core/test/integration/exporter/exporter.test.js +++ b/ghost/core/test/integration/exporter/exporter.test.js @@ -24,6 +24,7 @@ describe('Exporter', function () { const tables = [ 'actions', 'api_keys', + 'benefits', 'brute', 'collections', 'collections_posts', @@ -41,28 +42,28 @@ describe('Exporter', function () { 'invites', 'jobs', 'labels', - 'redirects', 'members', 'members_cancel_events', + 'members_click_events', + 'members_created_events', 'members_email_change_events', 'members_feedback', 'members_labels', - 'members_click_events', 'members_login_events', 'members_newsletters', 'members_paid_subscription_events', 'members_payment_events', + 'members_product_events', 'members_products', 'members_status_events', - 'members_product_events', 'members_stripe_customers', 'members_stripe_customers_subscriptions', 'members_subscribe_events', - 'members_created_events', 'members_subscription_created_events', 'mentions', 'migrations', 'migrations_lock', + 'milestones', 'mobiledoc_revisions', 'newsletters', 'offers', @@ -74,26 +75,26 @@ describe('Exporter', function () { 'posts', 'posts_authors', 'posts_meta', - 'posts_tags', 'posts_products', + 'posts_tags', 'products', - 'benefits', 'products_benefits', - 'stripe_products', - 'stripe_prices', - 'subscriptions', - 'suppressions', + 'recommendations', + 'redirects', 'roles', 'roles_users', 'sessions', 'settings', 'snippets', + 'stripe_prices', + 'stripe_products', + 'subscriptions', + 'suppressions', 'tags', + 'temp_mail_events', 'tokens', 'users', - 'webhooks', - 'milestones', - 'temp_mail_events' + 'webhooks' ]; should.exist(exportData); diff --git a/ghost/core/test/unit/server/data/schema/integrity.test.js b/ghost/core/test/unit/server/data/schema/integrity.test.js index bad7841e3b..316345aec3 100644 --- a/ghost/core/test/unit/server/data/schema/integrity.test.js +++ b/ghost/core/test/unit/server/data/schema/integrity.test.js @@ -35,7 +35,7 @@ const validateRouteSettings = require('../../../../../core/server/services/route */ describe('DB version integrity', function () { // Only these variables should need updating - const currentSchemaHash = 'ad44bf95fee71a878704bff2a313a583'; + const currentSchemaHash = '5674764ca6518961a9b2917e7d8e2ea9'; const currentFixturesHash = '31865c37aacfec9b8f16c1354b36a7de'; const currentSettingsHash = 'dd0e318627ded65e41f188fb5bdf5b74'; const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';