From 758aba0f7aa69150721c3d186f464b058b0c2832 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 3 Feb 2026 22:28:54 +0300 Subject: [PATCH] migrations: handle incramental/queued scans more gracefully Signed-off-by: NotAShelf Change-Id: I13ef3c7b03f3833e90a7bfcdb03ac0136a6a6964 --- migrations/postgres/V10__incremental_scan.sql | 19 +++++++++++++++++++ migrations/sqlite/V10__incremental_scan.sql | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 migrations/postgres/V10__incremental_scan.sql create mode 100644 migrations/sqlite/V10__incremental_scan.sql diff --git a/migrations/postgres/V10__incremental_scan.sql b/migrations/postgres/V10__incremental_scan.sql new file mode 100644 index 0000000..8fdc2cb --- /dev/null +++ b/migrations/postgres/V10__incremental_scan.sql @@ -0,0 +1,19 @@ +-- 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 BIGINT; + +-- 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 UUID PRIMARY KEY DEFAULT gen_random_uuid(), + directory TEXT NOT NULL UNIQUE, + last_scan_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + 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); diff --git a/migrations/sqlite/V10__incremental_scan.sql b/migrations/sqlite/V10__incremental_scan.sql new file mode 100644 index 0000000..76db5c9 --- /dev/null +++ b/migrations/sqlite/V10__incremental_scan.sql @@ -0,0 +1,19 @@ +-- 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);