-- Plex's addedAt tracks the FILE, not the library entry. Replacing or -- re-encoding a file resets Date Added while the item and its watch history -- survive, so 19% of the live library (22% of TV Show Archive) reports a -- lastViewedAt EARLIER than its addedAt — watched before it was "added". -- -- That matters beyond cosmetics: pre_history is derived from added_at, so an -- old item whose file was replaced looks post-coverage and lands in the -- CONFIDENT reclaim pool when it belongs in the uncertain one. -- -- Keep Plex's raw value for reference, and let added_at hold the best estimate -- (see ingest._correct_added_at). Also record when MediaShelf itself first saw -- a row, which is authoritative from now on regardless of what Plex does. ALTER TABLE media_item ADD COLUMN provider_added_at INTEGER; ALTER TABLE media_item ADD COLUMN added_at_source TEXT; ALTER TABLE media_item ADD COLUMN first_seen_at INTEGER; ALTER TABLE episode ADD COLUMN provider_added_at INTEGER; ALTER TABLE episode ADD COLUMN first_watched_at INTEGER; ALTER TABLE episode ADD COLUMN first_seen_at INTEGER; -- Backfill: existing rows carry Plex's value in added_at. UPDATE media_item SET provider_added_at = added_at WHERE provider_added_at IS NULL; UPDATE episode SET provider_added_at = added_at WHERE provider_added_at IS NULL; CREATE INDEX ix_item_first_seen ON media_item(first_seen_at);