refactor(sync): drop favorite-folder tracking and deal
This commit is contained in:
1 parent
62abbd7ea1
commit
6c4287b43a
21 files changed
+1390
-2766
No files matched your search
@@ -37,8 +37,8 @@ def test_fresh_and_idempotent():
|
||||
conn = sqlite3.connect(Path(tmp) / "app.db")
|
||||
try:
|
||||
applied = run_migrations(conn)
|
||||
assert applied == [1, 2, 3, 4]
|
||||
assert current_version(conn) == 4
|
||||
assert applied == [1, 2, 3, 4, 5]
|
||||
assert current_version(conn) == 5
|
||||
assert EXPECTED_TABLES <= table_names(conn)
|
||||
assert "schema_version" in table_names(conn)
|
||||
columns = {
|
||||
@@ -66,7 +66,7 @@ def test_fresh_and_idempotent():
|
||||
# 再跑一次不应重复应用
|
||||
assert run_migrations(conn) == []
|
||||
row = conn.execute("SELECT COUNT(*) FROM schema_version").fetchone()
|
||||
assert row[0] == 4
|
||||
assert row[0] == 5
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
@@ -81,15 +81,15 @@ def test_backup_before_upgrade():
|
||||
conn.execute("INSERT INTO kv(k, v) VALUES ('hello', 'world')")
|
||||
conn.commit()
|
||||
|
||||
v5 = Migration(5, "add probe", ("CREATE TABLE probe (id INTEGER PRIMARY KEY)",))
|
||||
v6 = Migration(6, "add probe", ("CREATE TABLE probe (id INTEGER PRIMARY KEY)",))
|
||||
applied = run_migrations(
|
||||
conn,
|
||||
backup_dir=backup_dir,
|
||||
now=1_800_000_000,
|
||||
migrations=MIGRATIONS + (v5,),
|
||||
migrations=MIGRATIONS + (v6,),
|
||||
)
|
||||
assert applied == [5]
|
||||
backups = list(backup_dir.glob("app-pre-v4-*.db"))
|
||||
assert applied == [6]
|
||||
backups = list(backup_dir.glob("app-pre-v5-*.db"))
|
||||
assert len(backups) == 1
|
||||
check = sqlite3.connect(backups[0])
|
||||
try:
|
||||
@@ -159,12 +159,35 @@ def test_validate_migration_order():
|
||||
conn.close()
|
||||
|
||||
|
||||
def test_v5_normalizes_unfaved():
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
conn = sqlite3.connect(Path(tmp) / "app.db")
|
||||
try:
|
||||
run_migrations(conn, migrations=MIGRATIONS[:4])
|
||||
conn.execute(
|
||||
"INSERT INTO video(aid, title, pubdate, status, first_seen) "
|
||||
"VALUES (1, 't', 1, 'unfaved', 1)"
|
||||
)
|
||||
conn.execute(
|
||||
"INSERT INTO video(aid, title, pubdate, status, first_seen) "
|
||||
"VALUES (2, 't', 1, 'dropped', 1)"
|
||||
)
|
||||
conn.commit()
|
||||
applied = run_migrations(conn)
|
||||
assert applied == [5]
|
||||
rows = dict(conn.execute("SELECT aid, status FROM video").fetchall())
|
||||
assert rows == {1: "active", 2: "dropped"}
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
def main():
|
||||
test_fresh_and_idempotent()
|
||||
test_backup_before_upgrade()
|
||||
test_failed_migration_rolls_back()
|
||||
test_prune_backups()
|
||||
test_validate_migration_order()
|
||||
test_v5_normalizes_unfaved()
|
||||
print("OK: SQLite 迁移、备份与回滚测试全部通过")
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user