Fixed watch history and make it consistent with progress items.

This commit is contained in:
Dum 2026-03-01 23:16:33 +05:30
parent 16f9905028
commit 8e8fd83164
2 changed files with 25 additions and 2 deletions

View file

@ -20,4 +20,27 @@ WHERE "season_id" IS NULL;
UPDATE "progress_items"
SET "episode_id" = E'\n'
WHERE "episode_id" IS NULL;
-- Normalize existing movie watch_history rows: NULL → '\n' sentinel
-- Same pattern as progress_items above.
-- Deduplicate: if both a NULL row and a '\n' row exist for the same movie,
-- keep the '\n' row and delete the NULL one.
DELETE FROM "watch_history" a
USING "watch_history" b
WHERE a."tmdb_id" = b."tmdb_id"
AND a."user_id" = b."user_id"
AND a."season_id" IS NULL
AND a."episode_id" IS NULL
AND b."season_id" = E'\n'
AND b."episode_id" = E'\n';
-- Convert remaining NULL rows to '\n'
UPDATE "watch_history"
SET "season_id" = E'\n'
WHERE "season_id" IS NULL;
UPDATE "watch_history"
SET "episode_id" = E'\n'
WHERE "episode_id" IS NULL;

View file

@ -113,8 +113,8 @@ export default defineEventHandler(async event => {
id: watchHistoryItem.id,
tmdbId: watchHistoryItem.tmdb_id,
userId: watchHistoryItem.user_id,
seasonId: watchHistoryItem.season_id,
episodeId: watchHistoryItem.episode_id,
seasonId: watchHistoryItem.season_id === '\n' ? null : watchHistoryItem.season_id,
episodeId: watchHistoryItem.episode_id === '\n' ? null : watchHistoryItem.episode_id,
seasonNumber: watchHistoryItem.season_number,
episodeNumber: watchHistoryItem.episode_number,
meta: watchHistoryItem.meta,