From 605125fbb5fce56496dd9ffeeb7f6fb78f9a1248 Mon Sep 17 00:00:00 2001 From: Jaanus Sellin Date: Thu, 18 Jan 2024 13:52:51 +0200 Subject: [PATCH] feat: add primary keys to missing tables (#5943) Follow up of https://github.com/Unleash/unleash/issues/4303 We are adding primary keys to all tables missing them, currently **role_permission**, **api_token_project**, and **project_stats**. By adding primary keys, the issue with migrations failing during upgrades in replicated database setups will be resolved. --- .../20240118093611-missing-primary-keys.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/migrations/20240118093611-missing-primary-keys.js diff --git a/src/migrations/20240118093611-missing-primary-keys.js b/src/migrations/20240118093611-missing-primary-keys.js new file mode 100644 index 000000000000..e6ba1ccd44d9 --- /dev/null +++ b/src/migrations/20240118093611-missing-primary-keys.js @@ -0,0 +1,24 @@ +'use strict'; + +exports.up = function (db, callback) { + db.runSql( + ` + ALTER TABLE project_stats ADD PRIMARY KEY (project); + ALTER TABLE api_token_project ADD PRIMARY KEY (secret, project); + ALTER TABLE role_permission ADD COLUMN id SERIAL PRIMARY KEY; + `, + callback, + ); +}; + +exports.down = function (db, callback) { + db.runSql( + ` + ALTER TABLE project_stats DROP CONSTRAINT project_stats_pkey; + ALTER TABLE api_token_project DROP CONSTRAINT api_token_project_pkey; + ALTER TABLE role_permission DROP CONSTRAINT role_permission_pkey; + ALTER TABLE role_permission DROP COLUMN id; + `, + callback, + ); +};