CREATE TABLE "file_download_logs" (
	"id" serial PRIMARY KEY NOT NULL,
	"file_id" integer NOT NULL,
	"user_id" varchar(50) NOT NULL,
	"user_email" varchar(255),
	"user_name" varchar(100),
	"user_role" varchar(50),
	"user_ip" "inet",
	"user_agent" text,
	"file_name" varchar(255),
	"file_path" varchar(500),
	"file_size" integer,
	"downloaded_at" timestamp with time zone DEFAULT now() NOT NULL,
	"success" boolean NOT NULL,
	"error_message" text,
	"session_id" varchar(100),
	"request_id" varchar(50),
	"referer" text,
	"download_duration_ms" integer
);
--> statement-breakpoint
CREATE TABLE "user_download_stats" (
	"id" serial PRIMARY KEY NOT NULL,
	"user_id" varchar(50) NOT NULL,
	"date" timestamp with time zone NOT NULL,
	"total_downloads" integer DEFAULT 0 NOT NULL,
	"total_bytes" integer DEFAULT 0 NOT NULL,
	"unique_files" integer DEFAULT 0 NOT NULL,
	"last_download_at" timestamp with time zone
);
