CREATE TABLE "account" (
	"id" text PRIMARY KEY NOT NULL,
	"account_id" text NOT NULL,
	"provider_id" text NOT NULL,
	"user_id" text NOT NULL,
	"access_token" text,
	"refresh_token" text,
	"id_token" text,
	"access_token_expires_at" timestamp with time zone,
	"refresh_token_expires_at" timestamp with time zone,
	"scope" text,
	"password" text,
	"created_at" timestamp with time zone DEFAULT now() NOT NULL,
	"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "es_lead" (
	"id" text PRIMARY KEY NOT NULL,
	"email" text NOT NULL,
	"source" text NOT NULL,
	"site_url" text,
	"consent" boolean DEFAULT false NOT NULL,
	"ip_address" text,
	"user_agent" text,
	"user_id" text,
	"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "session" (
	"id" text PRIMARY KEY NOT NULL,
	"expires_at" timestamp with time zone NOT NULL,
	"token" text NOT NULL,
	"ip_address" text,
	"user_agent" text,
	"user_id" text NOT NULL,
	"created_at" timestamp with time zone DEFAULT now() NOT NULL,
	"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "session_token_unique" UNIQUE("token")
);
--> statement-breakpoint
CREATE TABLE "es_site_test" (
	"id" text PRIMARY KEY NOT NULL,
	"site_id" text NOT NULL,
	"user_id" text NOT NULL,
	"url" text NOT NULL,
	"device" text,
	"status" text NOT NULL,
	"browser" text,
	"iterations" integer,
	"error" text,
	"created_at" timestamp with time zone DEFAULT now() NOT NULL,
	"completed_at" timestamp with time zone,
	"fcp" real,
	"lcp" real,
	"tbt" real,
	"cls" real,
	"ttfb" real,
	"fid" real,
	"si" real,
	"fully_loaded" real,
	"dom_content_loaded" real,
	"dom_interactive" real,
	"requests" integer,
	"transfer_size" integer,
	"lighthouse_perf" integer,
	"lighthouse_a11y" integer,
	"lighthouse_bp" integer,
	"lighthouse_seo" integer,
	"lighthouse_opportunities" jsonb,
	"lighthouse_diagnostics" jsonb,
	"resource_breakdown" jsonb,
	"performance_score" integer,
	"report_url" text,
	"lighthouse_report_url" text,
	"har_url" text,
	"screenshot_after" text,
	"screenshot_lcp" text,
	"screenshot_cls" text
);
--> statement-breakpoint
CREATE TABLE "es_site" (
	"id" text PRIMARY KEY NOT NULL,
	"user_id" text NOT NULL,
	"hostname" text NOT NULL,
	"url" text NOT NULL,
	"label" text,
	"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "user" (
	"id" text PRIMARY KEY NOT NULL,
	"name" text NOT NULL,
	"email" text NOT NULL,
	"email_verified" boolean DEFAULT false NOT NULL,
	"image" text,
	"created_at" timestamp with time zone DEFAULT now() NOT NULL,
	"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "user_email_unique" UNIQUE("email")
);
--> statement-breakpoint
CREATE TABLE "verification" (
	"id" text PRIMARY KEY NOT NULL,
	"identifier" text NOT NULL,
	"value" text NOT NULL,
	"expires_at" timestamp with time zone NOT NULL,
	"created_at" timestamp with time zone DEFAULT now(),
	"updated_at" timestamp with time zone DEFAULT now()
);
--> statement-breakpoint
ALTER TABLE "account" ADD CONSTRAINT "account_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "es_lead" ADD CONSTRAINT "es_lead_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "session" ADD CONSTRAINT "session_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "es_site_test" ADD CONSTRAINT "es_site_test_site_id_es_site_id_fk" FOREIGN KEY ("site_id") REFERENCES "public"."es_site"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "idx_lead_email" ON "es_lead" USING btree ("email");--> statement-breakpoint
CREATE INDEX "idx_lead_source" ON "es_lead" USING btree ("source");--> statement-breakpoint
CREATE INDEX "idx_site_test_site" ON "es_site_test" USING btree ("site_id");--> statement-breakpoint
CREATE INDEX "idx_site_test_user" ON "es_site_test" USING btree ("user_id");--> statement-breakpoint
CREATE INDEX "idx_site_test_created" ON "es_site_test" USING btree ("created_at");--> statement-breakpoint
CREATE INDEX "idx_site_user" ON "es_site" USING btree ("user_id");