ALTER TABLE "tenant_settings" ADD COLUMN "contract_default_template_id" uuid;--> statement-breakpoint
ALTER TABLE "tenant_settings" ADD COLUMN "contract_default_expiry_days" integer DEFAULT 365 NOT NULL;--> statement-breakpoint
ALTER TABLE "tenant_settings" ADD COLUMN "contract_default_signing_order" text DEFAULT 'parallel' NOT NULL;--> statement-breakpoint
ALTER TABLE "tenant_settings" ADD COLUMN "contract_require_email_verification" boolean DEFAULT true NOT NULL;--> statement-breakpoint
ALTER TABLE "tenant_settings" ADD COLUMN "contract_reminder_first_days" integer DEFAULT 3 NOT NULL;--> statement-breakpoint
ALTER TABLE "tenant_settings" ADD COLUMN "contract_reminder_followup_days" integer DEFAULT 7 NOT NULL;--> statement-breakpoint
ALTER TABLE "tenant_settings" ADD COLUMN "contract_reminder_max_count" integer DEFAULT 3 NOT NULL;--> statement-breakpoint
ALTER TABLE "tenant_settings" ADD COLUMN "contract_renewal_remind_30d" boolean DEFAULT true NOT NULL;--> statement-breakpoint
ALTER TABLE "tenant_settings" ADD COLUMN "contract_renewal_remind_7d" boolean DEFAULT true NOT NULL;--> statement-breakpoint
ALTER TABLE "tenant_settings" ADD COLUMN "contract_renewal_remind_1d" boolean DEFAULT false NOT NULL;--> statement-breakpoint
ALTER TABLE "tenant_settings" ADD COLUMN "contract_renewal_notify_email" boolean DEFAULT true NOT NULL;--> statement-breakpoint
ALTER TABLE "tenant_settings" ADD COLUMN "contract_renewal_notify_in_app" boolean DEFAULT true NOT NULL;--> statement-breakpoint
-- leads-detail-view (wave-13): add lead_id reverse-lookup FKs
ALTER TABLE "contracts" ADD COLUMN IF NOT EXISTS "lead_id" uuid REFERENCES leads(id) ON DELETE SET NULL;--> statement-breakpoint
ALTER TABLE "invoices" ADD COLUMN IF NOT EXISTS "lead_id" uuid REFERENCES leads(id) ON DELETE SET NULL;--> statement-breakpoint
ALTER TABLE "tasks" ADD COLUMN IF NOT EXISTS "lead_id" uuid REFERENCES leads(id) ON DELETE SET NULL;--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_contracts_lead" ON "contracts" ("lead_id") WHERE lead_id IS NOT NULL;--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_invoices_lead" ON "invoices" ("lead_id") WHERE lead_id IS NOT NULL;--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_tasks_lead" ON "tasks" ("lead_id") WHERE lead_id IS NOT NULL;