CREATE TYPE "router_v1.7"."position_type" AS ENUM('erc20', 'vault_v1');--> statement-breakpoint
CREATE TABLE "router_v1.7"."callbacks" (
	"id" varchar(66) PRIMARY KEY NOT NULL,
	"position_chain_id" bigint NOT NULL,
	"position_contract" varchar(42) NOT NULL,
	"position_user" varchar(42) NOT NULL,
	"amount" numeric(78, 0) NOT NULL
);
--> statement-breakpoint
CREATE TABLE "router_v1.7"."offers_callbacks" (
	"offer_hash" varchar(66) NOT NULL,
	"callback_id" varchar(66),
	CONSTRAINT "offers_callbacks_pk" PRIMARY KEY("offer_hash","callback_id")
);
--> statement-breakpoint
CREATE TABLE "router_v1.7"."position_types" (
	"id" serial PRIMARY KEY NOT NULL,
	"type" "router_v1.7"."position_type" NOT NULL
);
--> statement-breakpoint
CREATE TABLE "router_v1.7"."positions" (
	"chain_id" bigint NOT NULL,
	"contract" varchar(42) NOT NULL,
	"user" varchar(42) NOT NULL,
	"position_type_id" integer NOT NULL,
	"balance" numeric(78, 0),
	"block_number" bigint NOT NULL,
	"updated_at" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "positions_pk" PRIMARY KEY("chain_id","contract","user")
);
--> statement-breakpoint
ALTER TABLE "router_v1.7"."offer_status" DROP CONSTRAINT "offer_status_status_id_status_id_fk";
--> statement-breakpoint
ALTER TABLE "router_v1.7"."callbacks" ADD CONSTRAINT "callbacks_positions_fk" FOREIGN KEY ("position_chain_id","position_contract","position_user") REFERENCES "router_v1.7"."positions"("chain_id","contract","user") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "router_v1.7"."offers_callbacks" ADD CONSTRAINT "offers_callbacks_offer_hash_offers_v2_hash_fk" FOREIGN KEY ("offer_hash") REFERENCES "router_v1.7"."offers_v2"("hash") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "router_v1.7"."positions" ADD CONSTRAINT "positions_position_type_id_position_types_id_fk" FOREIGN KEY ("position_type_id") REFERENCES "router_v1.7"."position_types"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "router_v1.7"."offer_status" ADD CONSTRAINT "offer_status_status_id_status_id_fk" FOREIGN KEY ("status_id") REFERENCES "router_v1.7"."status"("id") ON DELETE no action ON UPDATE no action;