From 7039160af00349fc54f3c840bb8b58599fa59c81 Mon Sep 17 00:00:00 2001 From: Jaanus Sellin Date: Wed, 25 Oct 2023 14:09:34 +0300 Subject: [PATCH] fix: project mode can not be set to null anymore (#5145) --- src/lib/db/project-store.ts | 2 +- .../20231025093422-default-project-mode.js | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/migrations/20231025093422-default-project-mode.js diff --git a/src/lib/db/project-store.ts b/src/lib/db/project-store.ts index 7f04bff875..c419307c09 100644 --- a/src/lib/db/project-store.ts +++ b/src/lib/db/project-store.ts @@ -277,11 +277,11 @@ class ProjectStore implements IProjectStore { feature_limit: data.featureLimit, }); } else { - // What happens with project mode in this case? await this.db(SETTINGS_TABLE).insert({ project: data.id, default_stickiness: data.defaultStickiness, feature_limit: data.featureLimit, + project_mode: 'open', }); } } diff --git a/src/migrations/20231025093422-default-project-mode.js b/src/migrations/20231025093422-default-project-mode.js new file mode 100644 index 0000000000..aefd753708 --- /dev/null +++ b/src/migrations/20231025093422-default-project-mode.js @@ -0,0 +1,32 @@ +'use strict'; + +exports.up = function (db, cb) { + db.runSql(` + ALTER TABLE project_settings + ALTER COLUMN project_mode SET DEFAULT 'open'; + + UPDATE project_settings + SET project_mode = 'open' + WHERE project_mode NOT IN ('open', 'protected', 'private') OR project_mode IS NULL; + + ALTER TABLE project_settings + ALTER COLUMN project_mode SET NOT NULL; + + ALTER TABLE project_settings + ADD CONSTRAINT project_settings_project_mode_values + CHECK (project_mode IN ('open', 'protected', 'private')); + `, cb); +}; + +exports.down = function (db, cb) { + db.runSql(` + ALTER TABLE project_settings + ALTER COLUMN project_mode DROP DEFAULT; + + ALTER TABLE project_settings + ALTER COLUMN project_mode DROP NOT NULL; + + ALTER TABLE project_settings + DROP CONSTRAINT project_settings_project_mode_values; + `, cb); +};