second commit

This commit is contained in:
gosangam
2026-10-18 23:52:30 +05:30
parent 732a06f65d
commit 3ee8427dae
5 changed files with 286 additions and 6 deletions
+28
View File
@@ -153,3 +153,31 @@ def test_instance_lock_blocks_second_worker(config, db):
third = InstanceLock(config)
third.acquire()
third.release()
def test_upgrade_from_schema_v1_keeps_data(config, db_url):
"""An existing v1 deployment (before /upload tasks) migrates in place without data loss."""
import database as dbmod
v2 = dbmod.MIGRATIONS[1]
dbmod.MIGRATIONS.pop() # simulate the old code base
try:
old = Database.from_config(config)
with old._tx() as conn: # a row exactly as the v1 code wrote it
conn.execute(
"INSERT INTO videos (channel_id, message_id, state, indexes, title, discovered_at, updated_at) "
"VALUES (?,?,?,?,?,?,?)",
(CHANNEL_ID, 5, "DOWNLOADING", '["001", "002"]', "Class 01 Aman sir.mp4", "2026-01-01T00:00:00+00:00",
"2026-01-01T00:00:00+00:00"),
)
assert old.get_kv("schema_version") == "1"
old.close()
finally:
dbmod.MIGRATIONS.append(v2)
new = Database.from_config(config)
assert new.get_kv("schema_version") == "2"
rec = new.get((CHANNEL_ID, 5))
assert rec.state == State.DOWNLOADING and rec.task_id is None and rec.indexes == ["001", "002"]
task = new.create_task(111)
assert task.id == 1 and new.next_item(task_id=task.id) is None
new.close()