Files
accounted/supabase/migrations/20260402100000_voucher_number_unique_index.sql
Jakob Wennberg d0b3f21bde feat: remove AI extensions, restructure settings, and add atomic voucher commits (#157)
Remove AI-dependent extensions (ai-chat, ai-categorization, receipt-ocr,
invoice-inbox) and their infrastructure (lib/ai/*, ai-consent, LangChain/
Anthropic/OpenAI deps) to simplify core and reduce bundle size.

Restructure monolithic settings page into dedicated sub-pages (company,
bookkeeping, invoicing, tax, banking, api, account, team, templates) with
shared layout and sidebar navigation.

Add atomic commit_journal_entry RPC so voucher number increment and status
update happen in a single transaction — prevents burned numbers on constraint
failures. Add continuity check report and voucher gap explanation tracking.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 17:08:00 +02:00

7 lines
441 B
SQL

-- Partial unique index on journal_entries to prevent duplicate voucher numbers.
-- Drafts use voucher_number = 0 (integer NOT NULL), so WHERE > 0 excludes them.
-- This enforces BFL 5:7 at the database level — application logic alone is insufficient.
CREATE UNIQUE INDEX IF NOT EXISTS uq_journal_entries_voucher_number
ON public.journal_entries (company_id, fiscal_period_id, voucher_series, voucher_number)
WHERE voucher_number > 0;