fix(stats): preserve manual episode assignments across reparsing

This commit is contained in:
2026-08-14 01:51:35 -07:00
parent 8b71b38a26
commit 18790481ff
15 changed files with 435 additions and 38 deletions
+13
View File
@@ -80,6 +80,11 @@ test('merges remote-only sessions with catalog, lifetime, and rollups', () => {
{ headword: '食べる', word: '食べた', reading: 'たべた', count: 1 },
],
});
withWritableDb(remotePath, (db) => {
db.prepare(
`UPDATE imm_videos SET anime_assignment_locked = 1 WHERE video_key = 'showb-e1'`,
).run();
});
const summary = mergeSnapshotIntoDb(localPath, remotePath);
assert.equal(summary.sessionsMerged, 1);
@@ -126,6 +131,14 @@ test('merges remote-only sessions with catalog, lifetime, and rollups', () => {
`SELECT video_id FROM imm_videos WHERE video_key = 'showb-e1'`,
)?.video_id,
);
assert.equal(
queryOne<{ locked: number }>(
localPath,
'SELECT anime_assignment_locked AS locked FROM imm_videos WHERE video_id = ?',
[mergedVideoId],
)?.locked,
1,
);
assert.equal(
count(localPath, 'SELECT COUNT(*) AS n FROM imm_daily_rollups WHERE video_id = ?', [
mergedVideoId,
+2 -1
View File
@@ -1,4 +1,4 @@
// Schema-version-18 shape of the tables the sync merge touches (plus the
// Current schema shape of the tables the sync merge touches (plus the
// app's indexes), mirroring ensureSchema / ensureLifetimeSummaryTables /
// ensureStatsExcludedWordsTable in src/core/services/immersion-tracker/storage.ts.
export const IMMERSION_DB_FIXTURE_DDL = `
@@ -39,6 +39,7 @@ export const IMMERSION_DB_FIXTURE_DDL = `
parser_source TEXT,
parser_confidence REAL,
parse_metadata_json TEXT,
anime_assignment_locked INTEGER NOT NULL DEFAULT 0 CHECK(anime_assignment_locked IN (0, 1)),
watched INTEGER NOT NULL DEFAULT 0,
duration_ms INTEGER NOT NULL CHECK(duration_ms>=0),
file_size_bytes INTEGER CHECK(file_size_bytes>=0),