CREATE TABLE "router_v1.7"."merkle_paths" (
	"offer_hash" varchar(66) PRIMARY KEY NOT NULL,
	"tree_root" varchar(66) NOT NULL,
	"proof_nodes" text NOT NULL,
	"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "router_v1.7"."offsets" (
	"chain_id" bigint NOT NULL,
	"user" varchar(42) NOT NULL,
	"contract" varchar(42) NOT NULL,
	"group" varchar(66) NOT NULL,
	"value" numeric(78, 0) NOT NULL,
	CONSTRAINT "offsets_pk" PRIMARY KEY("chain_id","user","contract","group")
);
--> statement-breakpoint
CREATE TABLE "router_v1.7"."trees" (
	"root" varchar(66) PRIMARY KEY NOT NULL,
	"root_signature" varchar(132) NOT NULL,
	"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "router_v1.7"."merkle_paths" ADD CONSTRAINT "merkle_paths_offer_hash_offers_hash_fk" FOREIGN KEY ("offer_hash") REFERENCES "router_v1.7"."offers"("hash") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "router_v1.7"."merkle_paths" ADD CONSTRAINT "merkle_paths_tree_root_trees_root_fk" FOREIGN KEY ("tree_root") REFERENCES "router_v1.7"."trees"("root") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "router_v1.7"."offsets" ADD CONSTRAINT "offsets_positions_fk" FOREIGN KEY ("chain_id","contract","user") REFERENCES "router_v1.7"."positions"("chain_id","contract","user") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "merkle_paths_tree_root_idx" ON "router_v1.7"."merkle_paths" USING btree ("tree_root");