CREATE TABLE "deal_measure_approval_events" (
	"id" bigserial PRIMARY KEY NOT NULL,
	"hubspot_deal_id" text NOT NULL,
	"measure_name" text NOT NULL,
	"action" text NOT NULL,
	"acted_by" bigint NOT NULL,
	"acted_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "deal_measure_approvals" (
	"id" bigserial PRIMARY KEY NOT NULL,
	"hubspot_deal_id" text NOT NULL,
	"measure_name" text NOT NULL,
	"is_approved" boolean DEFAULT true NOT NULL,
	"approved_by" bigint NOT NULL,
	"approved_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "uq_deal_measure" UNIQUE("hubspot_deal_id","measure_name")
);
--> statement-breakpoint
DROP TABLE "deal_approvals" CASCADE;--> statement-breakpoint
DROP TABLE "deal_approved_measures" CASCADE;--> statement-breakpoint
ALTER TABLE "deal_measure_approval_events" ADD CONSTRAINT "deal_measure_approval_events_acted_by_user_id_fk" FOREIGN KEY ("acted_by") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "deal_measure_approvals" ADD CONSTRAINT "deal_measure_approvals_approved_by_user_id_fk" FOREIGN KEY ("approved_by") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "idx_deal_measure_events_deal_id" ON "deal_measure_approval_events" USING btree ("hubspot_deal_id");--> statement-breakpoint
CREATE INDEX "idx_deal_measure_events_acted_at" ON "deal_measure_approval_events" USING btree ("acted_at");--> statement-breakpoint
CREATE INDEX "idx_deal_measure_approvals_deal_id" ON "deal_measure_approvals" USING btree ("hubspot_deal_id");