DROP VIEW "public"."basic_contract_view";--> statement-breakpoint
ALTER TABLE "basic_contract_templates" ADD COLUMN "template_code" varchar(50) NOT NULL;--> statement-breakpoint
ALTER TABLE "basic_contract_templates" ADD COLUMN "revision" integer DEFAULT 1 NOT NULL;--> statement-breakpoint
ALTER TABLE "basic_contract_templates" ADD COLUMN "legal_review_required" boolean DEFAULT false NOT NULL;--> statement-breakpoint
ALTER TABLE "basic_contract_templates" ADD COLUMN "shipbuilding_applicable" boolean DEFAULT false NOT NULL;--> statement-breakpoint
ALTER TABLE "basic_contract_templates" ADD COLUMN "wind_applicable" boolean DEFAULT false NOT NULL;--> statement-breakpoint
ALTER TABLE "basic_contract_templates" ADD COLUMN "pc_applicable" boolean DEFAULT false NOT NULL;--> statement-breakpoint
ALTER TABLE "basic_contract_templates" ADD COLUMN "nb_applicable" boolean DEFAULT false NOT NULL;--> statement-breakpoint
ALTER TABLE "basic_contract_templates" ADD COLUMN "rc_applicable" boolean DEFAULT false NOT NULL;--> statement-breakpoint
ALTER TABLE "basic_contract_templates" ADD COLUMN "gy_applicable" boolean DEFAULT false NOT NULL;--> statement-breakpoint
ALTER TABLE "basic_contract_templates" ADD COLUMN "sys_applicable" boolean DEFAULT false NOT NULL;--> statement-breakpoint
ALTER TABLE "basic_contract_templates" ADD COLUMN "infra_applicable" boolean DEFAULT false NOT NULL;--> statement-breakpoint
ALTER TABLE "basic_contract_templates" ADD COLUMN "created_by" integer;--> statement-breakpoint
ALTER TABLE "basic_contract_templates" ADD COLUMN "updated_by" integer;--> statement-breakpoint
ALTER TABLE "basic_contract_templates" ADD COLUMN "disposed_at" timestamp;--> statement-breakpoint
ALTER TABLE "basic_contract_templates" ADD COLUMN "restored_at" timestamp;--> statement-breakpoint
ALTER TABLE "basic_contract_templates" ADD CONSTRAINT "basic_contract_templates_created_by_users_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "basic_contract_templates" ADD CONSTRAINT "basic_contract_templates_updated_by_users_id_fk" FOREIGN KEY ("updated_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "basic_contract_templates" ADD CONSTRAINT "basic_contract_templates_template_code_unique" UNIQUE("template_code");--> statement-breakpoint
CREATE VIEW "public"."basic_contract_view" AS (select "basic_contract"."id" as "id", "basic_contract"."template_id" as "template_id", "basic_contract"."vendor_id" as "vendor_id", "basic_contract"."requested_by" as "requested_by", "basic_contract"."status" as "basic_contract_status", "basic_contract"."created_at" as "created_at", "basic_contract"."updated_at" as "updated_at", "basic_contract"."completed_at" as "completed_at", "vendors"."vendor_code" as "vendor_code", "vendors"."email" as "vendor_email", "vendors"."vendor_name" as "vendor_name", "users"."name" as "requested_by_name", "basic_contract_templates"."template_code" as "template_code", "basic_contract_templates"."template_name" as "template_name", "basic_contract_templates"."revision" as "template_revision", "basic_contract_templates"."status" as "template_status", "basic_contract_templates"."validity_period" as "validity_period", "basic_contract_templates"."legal_review_required" as "legal_review_required", "basic_contract_templates"."shipbuilding_applicable" as "shipbuilding_applicable", "basic_contract_templates"."wind_applicable" as "wind_applicable", "basic_contract_templates"."pc_applicable" as "pc_applicable", "basic_contract_templates"."nb_applicable" as "nb_applicable", "basic_contract_templates"."rc_applicable" as "rc_applicable", "basic_contract_templates"."gy_applicable" as "gy_applicable", "basic_contract_templates"."sys_applicable" as "sys_applicable", "basic_contract_templates"."infra_applicable" as "infra_applicable", "basic_contract_templates"."file_path" as "template_file_path", "basic_contract_templates"."file_name" as "template_file_name", "basic_contract"."file_path" as "signed_file_path", "basic_contract"."file_name" as "signed_file_name", "basic_contract_templates"."created_at" as "template_created_at", "basic_contract_templates"."created_by" as "template_created_by", "basic_contract_templates"."updated_at" as "template_updated_at", "basic_contract_templates"."updated_by" as "template_updated_by", "basic_contract_templates"."disposed_at" as "template_disposed_at", "basic_contract_templates"."restored_at" as "template_restored_at" from "basic_contract" left join "vendors" on "basic_contract"."vendor_id" = "vendors"."id" left join "users" on "basic_contract"."requested_by" = "users"."id" left join "basic_contract_templates" on "basic_contract"."template_id" = "basic_contract_templates"."id");