CREATE TABLE "storage_files" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"tier_id" uuid NOT NULL,
	"media_item_id" uuid,
	"relative_path" text NOT NULL,
	"full_path" text NOT NULL,
	"filename" text NOT NULL,
	"extension" text NOT NULL,
	"size_bytes" bigint NOT NULL,
	"modified_at" timestamp NOT NULL,
	"observed_at" timestamp DEFAULT now() NOT NULL,
	"missing_at" timestamp,
	"inferred_title" text,
	"inferred_year" text,
	"quality" text,
	"codec" text
);
--> statement-breakpoint
ALTER TABLE "storage_files" ADD CONSTRAINT "storage_files_tier_id_storage_tiers_id_fk" FOREIGN KEY ("tier_id") REFERENCES "public"."storage_tiers"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "storage_files" ADD CONSTRAINT "storage_files_media_item_id_media_items_id_fk" FOREIGN KEY ("media_item_id") REFERENCES "public"."media_items"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
CREATE UNIQUE INDEX "storage_files_tier_relative_path_idx" ON "storage_files" USING btree ("tier_id","relative_path");