feat(db): add chunk_index table for Smart-Resume (sha1 of HLS segments)
UNIQUE(item_id, chunk_seq) + indices on item_id and sha1_hex. 1 new db test (127 total). No producer wired up yet — that comes with the Plan 04b integration into the live recorder. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
eac1dac180
commit
3667233a26
@ -72,6 +72,24 @@ describe('openDatabase', () => {
|
|||||||
expect(c?.c).toBe(2);
|
expect(c?.c).toBe(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('chunk_index table accepts insert + UNIQUE(item_id, chunk_seq)', () => {
|
||||||
|
db = openDatabase(path.join(tmpDir, 'chunk.db'));
|
||||||
|
db.run(
|
||||||
|
'INSERT INTO chunk_index(item_id, chunk_seq, sha1_hex, bytes) VALUES (?, ?, ?, ?)',
|
||||||
|
['item1', 0, 'abc123', 1024]
|
||||||
|
);
|
||||||
|
const handle = db;
|
||||||
|
expect(() => {
|
||||||
|
handle.run(
|
||||||
|
'INSERT INTO chunk_index(item_id, chunk_seq, sha1_hex, bytes) VALUES (?, ?, ?, ?)',
|
||||||
|
['item1', 0, 'different', 2048]
|
||||||
|
);
|
||||||
|
}).toThrow(); // UNIQUE violation
|
||||||
|
const rows = handle.all<{ sha1_hex: string }>('SELECT sha1_hex FROM chunk_index WHERE item_id = ?', ['item1']);
|
||||||
|
expect(rows).toHaveLength(1);
|
||||||
|
expect(rows[0].sha1_hex).toBe('abc123');
|
||||||
|
});
|
||||||
|
|
||||||
test('oauth_accounts table exists and accepts insert', () => {
|
test('oauth_accounts table exists and accepts insert', () => {
|
||||||
db = openDatabase(path.join(tmpDir, 'oauth.db'));
|
db = openDatabase(path.join(tmpDir, 'oauth.db'));
|
||||||
db.run(
|
db.run(
|
||||||
|
|||||||
@ -64,6 +64,19 @@ CREATE TABLE IF NOT EXISTS archive_files (
|
|||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_archive_streamer ON archive_files(streamer_login);
|
CREATE INDEX IF NOT EXISTS idx_archive_streamer ON archive_files(streamer_login);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS chunk_index (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
item_id TEXT NOT NULL,
|
||||||
|
chunk_seq INTEGER NOT NULL,
|
||||||
|
sha1_hex TEXT NOT NULL,
|
||||||
|
bytes INTEGER NOT NULL,
|
||||||
|
created_at INTEGER NOT NULL DEFAULT (strftime('%s','now')),
|
||||||
|
UNIQUE(item_id, chunk_seq)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_chunk_item ON chunk_index(item_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_chunk_sha1 ON chunk_index(sha1_hex);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS oauth_accounts (
|
CREATE TABLE IF NOT EXISTS oauth_accounts (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
provider TEXT NOT NULL,
|
provider TEXT NOT NULL,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user