CREATE TABLE "security_events" (
	"id" varchar(64) PRIMARY KEY NOT NULL,
	"type" varchar(64) NOT NULL,
	"user_id" varchar(64),
	"email" varchar(255),
	"ip_hash" varchar(64),
	"user_agent" varchar(255),
	"metadata_json" jsonb,
	"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "security_events" ADD CONSTRAINT "security_events_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "idx_security_events_type_created" ON "security_events" USING btree ("type","created_at");--> statement-breakpoint
CREATE INDEX "idx_security_events_user_created" ON "security_events" USING btree ("user_id","created_at");--> statement-breakpoint
CREATE INDEX "idx_security_events_ip_created" ON "security_events" USING btree ("ip_hash","created_at");