From dca27a9a3cddbd1666aa098461b9a77bd63326ab Mon Sep 17 00:00:00 2001 From: sjaanus Date: Thu, 18 Jan 2024 09:50:22 +0200 Subject: [PATCH 1/3] feat: add primary keys to missing tables --- .../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..a632a361000c --- /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); + 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, + ); +}; From 5d4891ac7bea1afaa6c28c398ca97d656c5f6343 Mon Sep 17 00:00:00 2001 From: sjaanus Date: Thu, 18 Jan 2024 10:13:51 +0200 Subject: [PATCH 2/3] Fix --- src/migrations/20240118093611-missing-primary-keys.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/migrations/20240118093611-missing-primary-keys.js b/src/migrations/20240118093611-missing-primary-keys.js index a632a361000c..eb6d4ec61e76 100644 --- a/src/migrations/20240118093611-missing-primary-keys.js +++ b/src/migrations/20240118093611-missing-primary-keys.js @@ -4,7 +4,7 @@ exports.up = function (db, callback) { db.runSql( ` ALTER TABLE project_stats ADD PRIMARY KEY (project); - ALTER TABLE api_token_project ADD PRIMARY KEY (secret); + ALTER TABLE api_token_project ADD COLUMN id SERIAL PRIMARY KEY; ALTER TABLE role_permission ADD COLUMN id SERIAL PRIMARY KEY; `, callback, @@ -16,6 +16,7 @@ exports.down = function (db, callback) { ` ALTER TABLE project_stats DROP CONSTRAINT project_stats_pkey; ALTER TABLE api_token_project DROP CONSTRAINT api_token_project_pkey; + ALTER TABLE api_token_project DROP COLUMN id; ALTER TABLE role_permission DROP CONSTRAINT role_permission_pkey; ALTER TABLE role_permission DROP COLUMN id; `, From 4982769213f4932a3c1c898fad1ea6484027c638 Mon Sep 17 00:00:00 2001 From: sjaanus Date: Thu, 18 Jan 2024 11:19:38 +0200 Subject: [PATCH 3/3] Fix --- src/migrations/20240118093611-missing-primary-keys.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/migrations/20240118093611-missing-primary-keys.js b/src/migrations/20240118093611-missing-primary-keys.js index eb6d4ec61e76..e6ba1ccd44d9 100644 --- a/src/migrations/20240118093611-missing-primary-keys.js +++ b/src/migrations/20240118093611-missing-primary-keys.js @@ -4,7 +4,7 @@ exports.up = function (db, callback) { db.runSql( ` ALTER TABLE project_stats ADD PRIMARY KEY (project); - ALTER TABLE api_token_project ADD COLUMN id SERIAL PRIMARY KEY; + ALTER TABLE api_token_project ADD PRIMARY KEY (secret, project); ALTER TABLE role_permission ADD COLUMN id SERIAL PRIMARY KEY; `, callback, @@ -16,7 +16,6 @@ exports.down = function (db, callback) { ` ALTER TABLE project_stats DROP CONSTRAINT project_stats_pkey; ALTER TABLE api_token_project DROP CONSTRAINT api_token_project_pkey; - ALTER TABLE api_token_project DROP COLUMN id; ALTER TABLE role_permission DROP CONSTRAINT role_permission_pkey; ALTER TABLE role_permission DROP COLUMN id; `,