From ca329da4b44a11f72aaa40ff9f4333afbec623cb Mon Sep 17 00:00:00 2001 From: Christopher Kolstad Date: Tue, 12 Mar 2024 13:36:21 +0100 Subject: [PATCH] fix: scim id was not unique (#6450) This PR drops the previous PRs scim_id idx and replaces it with an actual UNIQUE index --- .../20240305131822-add-scim-id-column-to-user.js | 4 ++-- src/migrations/20240306145609-make-scim-id-idx-unique.js | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 src/migrations/20240306145609-make-scim-id-idx-unique.js diff --git a/src/migrations/20240305131822-add-scim-id-column-to-user.js b/src/migrations/20240305131822-add-scim-id-column-to-user.js index 76e5229921..77d964f424 100644 --- a/src/migrations/20240305131822-add-scim-id-column-to-user.js +++ b/src/migrations/20240305131822-add-scim-id-column-to-user.js @@ -1,13 +1,13 @@ exports.up = function(db, cb) { db.runSql(` ALTER TABLE users ADD COLUMN scim_id TEXT; - CREATE INDEX users_scim_id_uniq_idx ON users (scim_id) WHERE scim_id IS NOT NULL; + CREATE INDEX IF NOT EXISTS users_scim_id_uniq_idx ON users (scim_id) WHERE scim_id IS NOT NULL; `, cb); }; exports.down = function(db, cb) { db.runSql(` - DROP INDEX users_scim_id_uniq_idx; + DROP INDEX IF EXISTS users_scim_id_uniq_idx; ALTER TABLE users DROP COLUMN scim_id; `, cb); }; diff --git a/src/migrations/20240306145609-make-scim-id-idx-unique.js b/src/migrations/20240306145609-make-scim-id-idx-unique.js new file mode 100644 index 0000000000..f430a72c4c --- /dev/null +++ b/src/migrations/20240306145609-make-scim-id-idx-unique.js @@ -0,0 +1,8 @@ +exports.up = function(db, cb) { + db.runSql(`DROP INDEX IF EXISTS users_scim_id_uniq_idx; + CREATE UNIQUE INDEX users_scim_id_unique_idx ON users(scim_id) WHERE scim_id IS NOT NULL`, cb); +}; + +exports.down = function(db, cb) { + db.runSql(`DROP INDEX IF EXISTS users_scim_id_unique_idx;`, cb); +};