ALTER TYPE "public"."consent_kind" ADD VALUE 'product_analytics';--> statement-breakpoint
CREATE TABLE "analytics_daily_snapshots" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"date" varchar(10) NOT NULL,
	"household_id" uuid,
	"event_name" varchar(64) NOT NULL,
	"count" integer DEFAULT 0 NOT NULL,
	"unique_sessions" integer DEFAULT 0 NOT NULL,
	"properties_fingerprint" varchar(64)
);
--> statement-breakpoint
CREATE TABLE "product_analytics_events" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"occurred_at" timestamp with time zone DEFAULT now() NOT NULL,
	"received_at" timestamp with time zone DEFAULT now() NOT NULL,
	"event_name" varchar(64) NOT NULL,
	"anonymous_id" varchar(64),
	"session_id" varchar(64),
	"user_id" uuid,
	"household_id" uuid,
	"app_version" varchar(32),
	"platform" varchar(16),
	"locale" varchar(16),
	"experiment_variant" varchar(128),
	"properties" jsonb DEFAULT '{}'::jsonb NOT NULL
);
--> statement-breakpoint
ALTER TABLE "analytics_daily_snapshots" ADD CONSTRAINT "analytics_daily_snapshots_household_id_households_id_fk" FOREIGN KEY ("household_id") REFERENCES "public"."households"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "product_analytics_events" ADD CONSTRAINT "product_analytics_events_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "product_analytics_events" ADD CONSTRAINT "product_analytics_events_household_id_households_id_fk" FOREIGN KEY ("household_id") REFERENCES "public"."households"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "pa_daily_household_date_idx" ON "analytics_daily_snapshots" USING btree ("household_id","date");--> statement-breakpoint
CREATE INDEX "pa_daily_date_event_idx" ON "analytics_daily_snapshots" USING btree ("date","event_name");--> statement-breakpoint
CREATE INDEX "pa_events_name_occurred_idx" ON "product_analytics_events" USING btree ("event_name","occurred_at");--> statement-breakpoint
CREATE INDEX "pa_events_household_occurred_idx" ON "product_analytics_events" USING btree ("household_id","occurred_at");--> statement-breakpoint
CREATE INDEX "pa_events_user_occurred_idx" ON "product_analytics_events" USING btree ("user_id","occurred_at");--> statement-breakpoint
CREATE INDEX "pa_events_session_idx" ON "product_analytics_events" USING btree ("session_id");--> statement-breakpoint
CREATE INDEX "pa_events_received_idx" ON "product_analytics_events" USING btree ("received_at");