1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-01 00:08:27 +01:00
unleash.unleash/src/migrations/20240118093611-missing-primary-keys.js
Jaanus Sellin 605125fbb5
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.
2024-01-18 13:52:51 +02:00

25 lines
702 B
JavaScript

'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,
);
};