diff --git a/CLAUDE.md b/CLAUDE.md index eecbbc99..53a63f79 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -83,7 +83,7 @@ lib/ types/index.ts Canonical type definitions (single source of truth) types/chat.ts Chat types tests/helpers.ts Mock factories and fixture builders -supabase/migrations/ SQL migration files (45 files) +supabase/migrations/ SQL migration files (63 files) extensions.config.json Extension opt-in configuration ``` @@ -265,14 +265,14 @@ Path params extracted as `_paramName` search params (e.g., `/:id` → `searchPar ## Database & Migrations -**Location**: `supabase/migrations/` — 45 files, numbered `20240101000001`–`20240101000045`. -**Next migration**: `20240101000052_*.sql` +**Location**: `supabase/migrations/` — 63 files. Early migrations use sequential numbering (`20240101000001`–`20240101000038`), later ones use real timestamps (`20260223150836`+). +**Next migration**: Use `mcp__plugin_supabase_supabase__apply_migration` which assigns timestamps automatically. ### Placeholder Migrations Some migrations are no-op placeholders to preserve the numbering sequence: -- **012** (`tax_codes`) — Planned but never deployed. The system operates without the `tax_codes` table. -- **023** (`document_version_chain`) — Planned but never deployed. Document versioning columns/functions do not exist in production. +- **012** (`tax_codes_placeholder`) — Planned but never deployed. The system operates without the `tax_codes` table. +- **023** (`document_version_chain_placeholder`) — Planned but never deployed. Document versioning columns/functions do not exist in production. ### Migration Rules @@ -296,14 +296,15 @@ Some migrations are no-op placeholders to preserve the numbering sequence: ### Recent Migrations -- **Migration 039 (`invoice_inbox`)** — Invoice inbox table with document type classification, AI extraction, supplier/transaction matching, and receipt linking. -- **Migration 040 (`booking_template_embeddings`)** — Booking templates with AI embeddings for suggestion matching. -- **Migration 041 (`user_description_matching`)** — User description matching for transaction categorization. -- **Migration 042 (`prevent_overlapping_fiscal_periods`)** — Exclusion constraint preventing overlapping fiscal periods per user. -- **Migration 043 (`enforce_fiscal_period_month_boundaries`)** — Ensures fiscal periods start/end on month boundaries. -- **Migration 044 (`full_bas_2026`)** — Full BAS 2026 account catalog, K2-excluded flag, and SRU code backfill. -- **Migration 045 (`expand_account_type_untaxed_reserves`)** — Adds `untaxed_reserves` to `chart_of_accounts.account_type` CHECK constraint for BAS 21xx accounts (obeskattade reserver). -- **Migration 051 (`set_search_path_on_functions`)** — Pins `search_path = public` on all 24 custom functions to prevent search_path injection. +- **`20260223150836_invoice_inbox`** — Invoice inbox table with document type classification, AI extraction, supplier/transaction matching, and receipt linking. +- **`20260224101905_booking_template_embeddings`** — Booking templates with AI embeddings for suggestion matching. +- **`20260224132419_user_description_matching`** — User description matching for transaction categorization. +- **`20260224165254_prevent_overlapping_fiscal_periods`** — Exclusion constraint preventing overlapping fiscal periods per user. +- **`20260224190818_enforce_fiscal_period_month_boundaries`** — Ensures fiscal periods start/end on month boundaries. +- **`20260225103139_full_bas_2026`** — Full BAS 2026 account catalog, K2-excluded flag, and SRU code backfill. +- **`20260226120553_expand_account_type_untaxed_reserves`** — Adds `untaxed_reserves` to `chart_of_accounts.account_type` CHECK constraint for BAS 21xx accounts (obeskattade reserver). +- **`20260304191528_set_search_path_on_functions`** — Pins `search_path = public` on all 24 custom functions to prevent search_path injection. +- **`20260306084837_invoice_delivery_note_sequences`** — Adds delivery note number sequence and `generate_invoice_number`/`generate_delivery_note_number` RPC functions. --- diff --git a/supabase/migrations/20240101000012_tax_codes.sql b/supabase/migrations/20240101000012_tax_codes_placeholder.sql similarity index 100% rename from supabase/migrations/20240101000012_tax_codes.sql rename to supabase/migrations/20240101000012_tax_codes_placeholder.sql diff --git a/supabase/migrations/20240101000023_document_version_chain.sql b/supabase/migrations/20240101000023_document_version_chain_placeholder.sql similarity index 100% rename from supabase/migrations/20240101000023_document_version_chain.sql rename to supabase/migrations/20240101000023_document_version_chain_placeholder.sql diff --git a/supabase/migrations/20240101000039_invoice_inbox.sql b/supabase/migrations/20260223150836_invoice_inbox.sql similarity index 100% rename from supabase/migrations/20240101000039_invoice_inbox.sql rename to supabase/migrations/20260223150836_invoice_inbox.sql diff --git a/supabase/migrations/20240101000040_booking_template_embeddings.sql b/supabase/migrations/20260224101905_booking_template_embeddings.sql similarity index 100% rename from supabase/migrations/20240101000040_booking_template_embeddings.sql rename to supabase/migrations/20260224101905_booking_template_embeddings.sql diff --git a/supabase/migrations/20260224132407_create_extension_data.sql b/supabase/migrations/20260224132407_create_extension_data.sql new file mode 100644 index 00000000..79bd1c34 --- /dev/null +++ b/supabase/migrations/20260224132407_create_extension_data.sql @@ -0,0 +1,4 @@ +-- Migration: create_extension_data +-- No-op: extension_data table is created by migration 020 (extension_data) +-- in this consolidated migration set. +-- Originally applied to production as a separate migration. diff --git a/supabase/migrations/20240101000041_user_description_matching.sql b/supabase/migrations/20260224132419_user_description_matching.sql similarity index 100% rename from supabase/migrations/20240101000041_user_description_matching.sql rename to supabase/migrations/20260224132419_user_description_matching.sql diff --git a/supabase/migrations/20260224142453_add_missing_dimension_columns.sql b/supabase/migrations/20260224142453_add_missing_dimension_columns.sql new file mode 100644 index 00000000..b679a08d --- /dev/null +++ b/supabase/migrations/20260224142453_add_missing_dimension_columns.sql @@ -0,0 +1,4 @@ +-- Migration: add_missing_dimension_columns +-- No-op: cost_center and project text columns on journal_entry_lines +-- are created by migration 011 (alter_existing_tables) in this consolidated set. +-- Originally applied to production as a separate migration. diff --git a/supabase/migrations/20260224142843_add_tax_code_column.sql b/supabase/migrations/20260224142843_add_tax_code_column.sql new file mode 100644 index 00000000..000b864c --- /dev/null +++ b/supabase/migrations/20260224142843_add_tax_code_column.sql @@ -0,0 +1,4 @@ +-- Migration: add_tax_code_column +-- No-op: tax_code column on journal_entry_lines +-- is created by migration 011 (alter_existing_tables) in this consolidated set. +-- Originally applied to production as a separate migration. diff --git a/supabase/migrations/20240101000042_prevent_overlapping_fiscal_periods.sql b/supabase/migrations/20260224165254_prevent_overlapping_fiscal_periods.sql similarity index 100% rename from supabase/migrations/20240101000042_prevent_overlapping_fiscal_periods.sql rename to supabase/migrations/20260224165254_prevent_overlapping_fiscal_periods.sql diff --git a/supabase/migrations/20240101000043_enforce_fiscal_period_month_boundaries.sql b/supabase/migrations/20260224190818_enforce_fiscal_period_month_boundaries.sql similarity index 100% rename from supabase/migrations/20240101000043_enforce_fiscal_period_month_boundaries.sql rename to supabase/migrations/20260224190818_enforce_fiscal_period_month_boundaries.sql diff --git a/supabase/migrations/20260225100240_document_inbox_expansion.sql b/supabase/migrations/20260225100240_document_inbox_expansion.sql new file mode 100644 index 00000000..505f7a42 --- /dev/null +++ b/supabase/migrations/20260225100240_document_inbox_expansion.sql @@ -0,0 +1,5 @@ +-- Migration: document_inbox_expansion +-- No-op: all document inbox columns (matched_transaction_id, match_confidence, +-- match_method, suggested_template_id, etc.) are included in the +-- invoice_inbox migration (20260223150836) in this consolidated set. +-- Originally applied to production as a separate migration. diff --git a/supabase/migrations/20260225100248_supplier_invoice_transaction_match.sql b/supabase/migrations/20260225100248_supplier_invoice_transaction_match.sql new file mode 100644 index 00000000..b2921c00 --- /dev/null +++ b/supabase/migrations/20260225100248_supplier_invoice_transaction_match.sql @@ -0,0 +1,10 @@ +-- Migration: supplier_invoice_transaction_match +-- Adds potential_supplier_invoice_id to transactions for supplier invoice matching. +-- Note: supplier_invoice_id on transactions is already added by migration 025 (payroll). + +ALTER TABLE public.transactions + ADD COLUMN IF NOT EXISTS potential_supplier_invoice_id UUID + REFERENCES public.supplier_invoices(id) ON DELETE SET NULL; + +CREATE INDEX IF NOT EXISTS idx_transactions_potential_supplier_invoice + ON public.transactions(potential_supplier_invoice_id); diff --git a/supabase/migrations/20240101000044_full_bas_2026.sql b/supabase/migrations/20260225103139_full_bas_2026.sql similarity index 100% rename from supabase/migrations/20240101000044_full_bas_2026.sql rename to supabase/migrations/20260225103139_full_bas_2026.sql diff --git a/supabase/migrations/20260225135645_document_matching.sql b/supabase/migrations/20260225135645_document_matching.sql new file mode 100644 index 00000000..b0d6f627 --- /dev/null +++ b/supabase/migrations/20260225135645_document_matching.sql @@ -0,0 +1,4 @@ +-- Migration: document_matching +-- No-op: match_documents function and knowledge_documents table +-- are created by migration 033 (ai_chat_schema) in this consolidated set. +-- Originally applied to production as a separate migration. diff --git a/supabase/migrations/20240101000045_expand_account_type_untaxed_reserves.sql b/supabase/migrations/20260226120553_expand_account_type_untaxed_reserves.sql similarity index 100% rename from supabase/migrations/20240101000045_expand_account_type_untaxed_reserves.sql rename to supabase/migrations/20260226120553_expand_account_type_untaxed_reserves.sql diff --git a/supabase/migrations/20260226154251_add_journal_entry_reversal_columns.sql b/supabase/migrations/20260226154251_add_journal_entry_reversal_columns.sql new file mode 100644 index 00000000..4ab99067 --- /dev/null +++ b/supabase/migrations/20260226154251_add_journal_entry_reversal_columns.sql @@ -0,0 +1,5 @@ +-- Migration: add_journal_entry_reversal_columns +-- No-op: reversed_by_id, reverses_id, correction_of_id, and committed_at columns +-- on journal_entries are created by migration 011 (alter_existing_tables) +-- in this consolidated set. +-- Originally applied to production as a separate migration. diff --git a/supabase/migrations/20260226161915_recreate_supplier_invoices_schema.sql b/supabase/migrations/20260226161915_recreate_supplier_invoices_schema.sql new file mode 100644 index 00000000..07fa0cb9 --- /dev/null +++ b/supabase/migrations/20260226161915_recreate_supplier_invoices_schema.sql @@ -0,0 +1,5 @@ +-- Migration: recreate_supplier_invoices_schema +-- No-op: suppliers, supplier_invoices, supplier_invoice_items, and +-- supplier_invoice_payments tables are created by migration 025 (supplier_invoices) +-- in this consolidated set with the final schema. +-- Originally applied to production as a separate migration. diff --git a/supabase/migrations/20260226162634_align_suppliers_schema.sql b/supabase/migrations/20260226162634_align_suppliers_schema.sql new file mode 100644 index 00000000..7cd70392 --- /dev/null +++ b/supabase/migrations/20260226162634_align_suppliers_schema.sql @@ -0,0 +1,5 @@ +-- Migration: align_suppliers_schema +-- No-op: supplier schema alignment (supplier_type, address_line2, +-- bank_account, default_expense_account, default_currency columns) +-- is included in migration 025 (supplier_invoices) in this consolidated set. +-- Originally applied to production as a separate migration. diff --git a/supabase/migrations/20260226162913_add_supplier_invoice_items_vat_code.sql b/supabase/migrations/20260226162913_add_supplier_invoice_items_vat_code.sql new file mode 100644 index 00000000..6588b556 --- /dev/null +++ b/supabase/migrations/20260226162913_add_supplier_invoice_items_vat_code.sql @@ -0,0 +1,4 @@ +-- Migration: add_supplier_invoice_items_vat_code +-- No-op: vat_code column on supplier_invoice_items is included in +-- migration 025 (supplier_invoices) in this consolidated set. +-- Originally applied to production as a separate migration. diff --git a/supabase/migrations/20260226163135_fix_audit_triggers_child_tables.sql b/supabase/migrations/20260226163135_fix_audit_triggers_child_tables.sql new file mode 100644 index 00000000..db729c48 --- /dev/null +++ b/supabase/migrations/20260226163135_fix_audit_triggers_child_tables.sql @@ -0,0 +1,4 @@ +-- Migration: fix_audit_triggers_child_tables +-- No-op: audit triggers on suppliers and supplier_invoices are included +-- in migration 025 (supplier_invoices) in this consolidated set. +-- Originally applied to production as a separate migration. diff --git a/supabase/migrations/20240101000046_chat_artifacts.sql b/supabase/migrations/20260226201355_chat_artifacts.sql similarity index 100% rename from supabase/migrations/20240101000046_chat_artifacts.sql rename to supabase/migrations/20260226201355_chat_artifacts.sql diff --git a/supabase/migrations/20240101000047_ai_usage_tracking.sql b/supabase/migrations/20260302095533_ai_usage_tracking.sql similarity index 100% rename from supabase/migrations/20240101000047_ai_usage_tracking.sql rename to supabase/migrations/20260302095533_ai_usage_tracking.sql diff --git a/supabase/migrations/20240101000048_supplier_invoice_overdue_cron.sql b/supabase/migrations/20260303145744_supplier_invoice_overdue_cron.sql similarity index 100% rename from supabase/migrations/20240101000048_supplier_invoice_overdue_cron.sql rename to supabase/migrations/20260303145744_supplier_invoice_overdue_cron.sql diff --git a/supabase/migrations/20240101000049_currency_revaluation_source_type.sql b/supabase/migrations/20260304075837_currency_revaluation_source_type.sql similarity index 100% rename from supabase/migrations/20240101000049_currency_revaluation_source_type.sql rename to supabase/migrations/20260304075837_currency_revaluation_source_type.sql diff --git a/supabase/migrations/20240101000051_set_search_path_on_functions.sql b/supabase/migrations/20260304191528_set_search_path_on_functions.sql similarity index 100% rename from supabase/migrations/20240101000051_set_search_path_on_functions.sql rename to supabase/migrations/20260304191528_set_search_path_on_functions.sql diff --git a/supabase/migrations/20240101000052_fix_vat_account_names.sql b/supabase/migrations/20260305161912_fix_vat_account_names.sql similarity index 100% rename from supabase/migrations/20240101000052_fix_vat_account_names.sql rename to supabase/migrations/20260305161912_fix_vat_account_names.sql diff --git a/supabase/migrations/20240101000050_invoice_delivery_note_sequences.sql b/supabase/migrations/20260306084837_invoice_delivery_note_sequences.sql similarity index 98% rename from supabase/migrations/20240101000050_invoice_delivery_note_sequences.sql rename to supabase/migrations/20260306084837_invoice_delivery_note_sequences.sql index 506924ef..ee25d093 100644 --- a/supabase/migrations/20240101000050_invoice_delivery_note_sequences.sql +++ b/supabase/migrations/20260306084837_invoice_delivery_note_sequences.sql @@ -17,6 +17,7 @@ CREATE OR REPLACE FUNCTION public.generate_invoice_number(p_user_id UUID) RETURNS TEXT LANGUAGE plpgsql SECURITY DEFINER +SET search_path = public AS $$ DECLARE v_prefix TEXT; @@ -51,6 +52,7 @@ CREATE OR REPLACE FUNCTION public.generate_delivery_note_number(p_user_id UUID) RETURNS TEXT LANGUAGE plpgsql SECURITY DEFINER +SET search_path = public AS $$ DECLARE v_number INTEGER;