fix: align local migrations with deployed Supabase state

Rename migration files (039-052) from sequential to real deployed
timestamps, add 11 missing migration files that were applied directly
to production, apply invoice_delivery_note_sequences migration, and
rename placeholder files for clarity.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jakob Wennberg
2026-03-06 10:16:22 +01:00
parent 55e8cc1a88
commit b0de46790a
28 changed files with 70 additions and 13 deletions
+14 -13
View File
@@ -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.
---
@@ -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.
@@ -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.
@@ -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.
@@ -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.
@@ -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);
@@ -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.
@@ -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.
@@ -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.
@@ -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.
@@ -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.
@@ -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.
@@ -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;