From c667620d8f2e32c96fe376ad0f3dabc79488532a Mon Sep 17 00:00:00 2001 From: Naz Date: Thu, 21 Jul 2022 10:33:28 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=97=20Added=20jobs=20table=20creation?= =?UTF-8?q?=20migration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refs https://github.com/TryGhost/Toolbox/issues/357 - One time jobs need a storage mechanism to be run only ever once. - Field notes: - `id`, `created_at`, `updated_at` - standard Ghost fields - `name` - unique name of the job, could also be used with prefixing to identify certain type of job (e.g.: backup-bob-2022-10-16, backup-sam-2023-01-13 identifying backup jobs run by users) - `status` - 'started' | 'finished' | 'failed' | 'queued' (need to identify when the job is in progress, done, added to the execution queue, or errored) - `started_at` - when the job started execution - `finished_at` - when the job successfully finished execution --- ghost/core/core/server/data/exporter/table-lists.js | 3 ++- .../versions/5.5/2022-07-21-08-56-add-jobs-table.js | 11 +++++++++++ ghost/core/core/server/data/schema/schema.js | 9 +++++++++ ghost/core/test/integration/exporter/exporter.test.js | 1 + .../test/unit/server/data/schema/integrity.test.js | 2 +- 5 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 ghost/core/core/server/data/migrations/versions/5.5/2022-07-21-08-56-add-jobs-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 763dbc1a38..2dfb3ea256 100644 --- a/ghost/core/core/server/data/exporter/table-lists.js +++ b/ghost/core/core/server/data/exporter/table-lists.js @@ -34,7 +34,8 @@ const BACKUP_TABLES = [ 'members_newsletters', 'comments', 'comment_likes', - 'comment_reports' + 'comment_reports', + 'jobs' ]; // 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.5/2022-07-21-08-56-add-jobs-table.js b/ghost/core/core/server/data/migrations/versions/5.5/2022-07-21-08-56-add-jobs-table.js new file mode 100644 index 0000000000..30d818c0ee --- /dev/null +++ b/ghost/core/core/server/data/migrations/versions/5.5/2022-07-21-08-56-add-jobs-table.js @@ -0,0 +1,11 @@ +const {addTable} = require('../../utils'); + +module.exports = addTable('jobs', { + id: {type: 'string', maxlength: 24, nullable: false, primary: true}, + name: {type: 'string', maxlength: 191, nullable: false, unique: true}, + status: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'queued', validations: {isIn: [['started', 'finished', 'failed', 'queued']]}}, + started_at: {type: 'dateTime', nullable: true}, + finished_at: {type: 'dateTime', nullable: true}, + 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 7e9f608f80..85b13a7b73 100644 --- a/ghost/core/core/server/data/schema/schema.js +++ b/ghost/core/core/server/data/schema/schema.js @@ -771,5 +771,14 @@ module.exports = { member_id: {type: 'string', maxlength: 24, nullable: true, unique: false, references: 'members.id', setNullDelete: true}, created_at: {type: 'dateTime', nullable: false}, updated_at: {type: 'dateTime', nullable: false} + }, + jobs: { + id: {type: 'string', maxlength: 24, nullable: false, primary: true}, + name: {type: 'string', maxlength: 191, nullable: false, unique: true}, + status: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'queued', validations: {isIn: [['started', 'finished', 'failed', 'queued']]}}, + started_at: {type: 'dateTime', nullable: true}, + finished_at: {type: 'dateTime', nullable: true}, + 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 eb8509a1cd..179a245eae 100644 --- a/ghost/core/test/integration/exporter/exporter.test.js +++ b/ghost/core/test/integration/exporter/exporter.test.js @@ -34,6 +34,7 @@ describe('Exporter', function () { 'emails', 'integrations', 'invites', + 'jobs', 'labels', 'members', 'members_cancel_events', 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 d50f50d704..4d2c8a5f22 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 = '6ca68654d9dcb05cf054b0a74f0de2c7'; + const currentSchemaHash = '71daf7814834fffd40abba86a92f4347'; const currentFixturesHash = 'a42105cc0d47dd978dd52ee271340013'; const currentSettingsHash = 'd54210758b7054e2174fd34aa2320ad7'; const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';