-- 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;