ALTER TABLE "proposals" DROP CONSTRAINT "proposals_status_check";--> statement-breakpoint
ALTER TABLE "contracts" ADD COLUMN "renewed_from_id" uuid;--> statement-breakpoint
ALTER TABLE "contracts" ADD COLUMN "amended_from_id" uuid;--> statement-breakpoint
ALTER TABLE "contracts" ADD COLUMN "effective_date" date;--> statement-breakpoint
ALTER TABLE "contracts" ADD COLUMN "expiry_date" date;--> statement-breakpoint
ALTER TABLE "tenant_settings" ADD COLUMN "proposal_default_valid_days" integer;--> statement-breakpoint
ALTER TABLE "kb_articles" ADD COLUMN IF NOT EXISTS "meta_title" text;--> statement-breakpoint
ALTER TABLE "kb_articles" ADD COLUMN IF NOT EXISTS "meta_description" text;--> statement-breakpoint
ALTER TABLE "kb_articles" ADD COLUMN IF NOT EXISTS "deleted_at" timestamp with time zone;--> statement-breakpoint
ALTER TABLE "kb_articles" ADD COLUMN IF NOT EXISTS "search_text" text GENERATED ALWAYS AS (title || ' ' || COALESCE(meta_title, '') || ' ' || COALESCE(meta_description, '')) STORED;--> statement-breakpoint
ALTER TABLE "contracts" ADD CONSTRAINT "contracts_renewed_from_id_contracts_id_fk" FOREIGN KEY ("renewed_from_id") REFERENCES "public"."contracts"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "contracts" ADD CONSTRAINT "contracts_amended_from_id_contracts_id_fk" FOREIGN KEY ("amended_from_id") REFERENCES "public"."contracts"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "proposals" ADD CONSTRAINT "proposals_status_check" CHECK ("proposals"."status" IN ('draft','sent','viewed','accepted','rejected','expired'));