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); +};