-- T8 — order model share attribution companion table (replaces purchases.share_slug_id).

CREATE TABLE "order_share_attribution" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"order_id" uuid NOT NULL,
	"share_slug_id" uuid NOT NULL,
	"created_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "order_share_attribution_order_id_key" UNIQUE("order_id")
);
--> statement-breakpoint
ALTER TABLE "order_share_attribution" ADD CONSTRAINT "order_share_attribution_share_slug_id_share_links_id_fk" FOREIGN KEY ("share_slug_id") REFERENCES "public"."share_links"("id") ON DELETE cascade ON UPDATE no action;
--> statement-breakpoint
CREATE INDEX "order_share_attr_share_slug_idx" ON "order_share_attribution" USING btree ("share_slug_id");
