-- invoices-core W3: DB-level idempotency for automated invoice generation
ALTER TABLE invoices ADD COLUMN IF NOT EXISTS dedup_key TEXT;
--> statement-breakpoint

-- raw_ddl: partial unique index (drizzle-kit cannot express WHERE clause)
CREATE UNIQUE INDEX IF NOT EXISTS invoices_tenant_dedup_key_uniq
  ON invoices (tenant_id, dedup_key)
  WHERE dedup_key IS NOT NULL;
