-- recurring-invoices: period-keyed idempotency for generated invoices
ALTER TABLE invoices ADD COLUMN IF NOT EXISTS recurring_period_start DATE;
--> statement-breakpoint

CREATE UNIQUE INDEX IF NOT EXISTS invoices_recurring_template_period_uniq
  ON invoices (recurring_template_id, recurring_period_start)
  WHERE recurring_template_id IS NOT NULL AND recurring_period_start IS NOT NULL;
