From 72ce28a5414163a6a578017e9a879ca3042b0dcc Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Tue, 8 Mar 2022 14:33:35 +0800 Subject: [PATCH] Migrate status page table --- db/patch-status-page.sql | 2 +- server/database.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/db/patch-status-page.sql b/db/patch-status-page.sql index 18986403c..07eacc023 100644 --- a/db/patch-status-page.sql +++ b/db/patch-status-page.sql @@ -9,7 +9,7 @@ CREATE TABLE [status_page]( [theme] VARCHAR(30) NOT NULL, [published] BOOLEAN NOT NULL DEFAULT 1, [search_engine_index] BOOLEAN NOT NULL DEFAULT 1, - [public] BOOLEAN NOT NULL DEFAULT 1, + [show_tags] BOOLEAN NOT NULL DEFAULT 0, [password] VARCHAR ); diff --git a/server/database.js b/server/database.js index fcef91719..119289e6a 100644 --- a/server/database.js +++ b/server/database.js @@ -171,6 +171,7 @@ class Database { } await this.patch2(); + await this.migrateNewStatusPage(); } /** @@ -212,6 +213,39 @@ class Database { await setSetting("databasePatchedFiles", databasePatchedFiles); } + /** + * Migrate status page value in setting to "status_page" table + * @returns {Promise} + */ + static async migrateNewStatusPage() { + let title = await setting("title"); + + if (title) { + console.log("Migrating Status Page"); + + let statusPageCheck = await R.findOne("status_page", " slug = '' "); + + if (statusPageCheck !== null) { + console.log("Migrating Status Page - Fail, empty slug record is already existing"); + return; + } + + let statusPage = R.dispense("status_page"); + statusPage.slug = ""; + statusPage.title = title; + statusPage.icon = await setting("icon"); + statusPage.theme = await setting("statusPageTheme"); + statusPage.published = await setting("statusPagePublished"); + statusPage.search_engine_index = await setting("searchEngineIndex"); + statusPage.show_tags = await setting("statusPageTags"); + statusPage.password = null; + await R.store(statusPage); + await R.exec("DELETE FROM setting WHERE type = 'statusPage'"); + console.log("Migrating Status Page - Done"); + } + + } + /** * Used it patch2() only * @param sqlFilename