fix(import): company-scope the bank_file_imports dedup key (#925)
* fix(import): company-scope the bank_file_imports dedup key The bank_file_imports unique constraint was (user_id, file_hash), predating multi-tenancy: a user importing the same statement file into a second company hit an upsert that resolved onto the first company's row, which RLS rejected (42501). Widen it to (company_id, file_hash) - the swap 20260330130000 made for sie_imports but missed here - and drop the now-obsolete BANK_IMPORT_DUPLICATE_OTHER_COMPANY cross-company pre-check from the v1 route (the structured-error code stays for API compat). The migration was already applied to prod; committing it reconciles the orphan (prod schema_migrations had 20260707130000 with no matching repo file). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * docs(import): fix stale unique-constraint comment (CodeRabbit) The completion-update comment still described the old (user_id, file_hash) constraint; it is (company_id, file_hash) since 20260707130000. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
19cbb0094b
commit
63e05c4eec
@@ -0,0 +1,14 @@
|
||||
-- bank_file_imports dedup key: (user_id, file_hash) -> (company_id, file_hash).
|
||||
-- The old key predates multi-tenancy: it blocked the same user from importing
|
||||
-- the same statement file into two different companies (upsert resolved onto
|
||||
-- the other company's row, and RLS correctly rejected the cross-company
|
||||
-- UPDATE with 42501). The 20260330130000 refactor made this exact swap for
|
||||
-- sie_imports but missed bank_file_imports. Verified in prod before this
|
||||
-- migration: no duplicate (company_id, file_hash) pairs exist.
|
||||
ALTER TABLE public.bank_file_imports
|
||||
DROP CONSTRAINT IF EXISTS bank_file_imports_user_id_file_hash_key;
|
||||
ALTER TABLE public.bank_file_imports
|
||||
ADD CONSTRAINT bank_file_imports_company_id_file_hash_key
|
||||
UNIQUE (company_id, file_hash);
|
||||
|
||||
NOTIFY pgrst, 'reload schema';
|
||||
Reference in New Issue
Block a user