pinakes/crates/pinakes-migrations/migrations/sqlite/V10__incremental_scan.sql
NotAShelf 9f9aa80265
treewide: move migration logic into pinakes-migrations crate
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I98b8ed2eee464ecfd42f492dec49adeb6a6a6964
2026-05-24 14:25:53 +03:00

19 lines
727 B
SQL

-- Add file_mtime column to media_items table for incremental scanning
-- Stores Unix timestamp in seconds of the file's modification time
ALTER TABLE media_items
ADD COLUMN file_mtime INTEGER;
-- Create index for quick mtime lookups
CREATE INDEX IF NOT EXISTS idx_media_items_file_mtime ON media_items (file_mtime);
-- Create a scan_history table to track when each directory was last scanned
CREATE TABLE IF NOT EXISTS scan_history (
id TEXT PRIMARY KEY,
directory TEXT NOT NULL UNIQUE,
last_scan_at TEXT NOT NULL,
files_scanned INTEGER NOT NULL DEFAULT 0,
files_changed INTEGER NOT NULL DEFAULT 0,
scan_duration_ms INTEGER
);
CREATE INDEX IF NOT EXISTS idx_scan_history_directory ON scan_history (directory);