Files
online-backend/db/migrations/20260918120000_add_branch_user_unique_index.up.sql
GuwandykA 0971158e98
Some checks failed
CI/CD / Vet, test, build (push) Has been cancelled
CI/CD / Docker image (push) Has been cancelled
CI/CD / Deploy binary to server (push) Has been cancelled
ch users <-> branches
2026-09-18 22:59:58 +05:00

15 lines
803 B
SQL

-- branch_user_branch_id_user_id_idx has been added in place to
-- 20260905130000_add_soft_delete.up.sql for fresh databases, but per this
-- project's migration convention (see 20260905150000_widen_loan_paid_off_letters_region),
-- that edit alone does not reach a database that was migrated before the
-- edit. This migration adds the index there too. Running it against a
-- database created after the edit is a harmless no-op.
--
-- The index scopes branch_user's many-to-many pairing (a user may belong to
-- several branches) to one active row per (branch_id, user_id) pair, so the
-- application can upsert an assignment instead of creating duplicate rows.
CREATE UNIQUE INDEX IF NOT EXISTS branch_user_branch_id_user_id_idx
ON branch_user (branch_id, user_id)
WHERE deleted_at IS NULL;