feat(db): add video pages and up follower snapshot schema

This commit is contained in:
kairee committed 2026-11-01 11:14:36 +08:00
1 parent 707ed7d7d7
commit 4942d1d161
10 files changed
+521 -13

No files matched your search

+22 -8
View File
@@ -21,7 +21,7 @@ from reaction_board.migrations import ( # noqa: E402
EXPECTED_TABLES = {
"video", "snapshot", "folder", "folder_resource", "up_blacklist",
"up_stat", "candidate", "seen_aid", "notify", "fav_action", "kv",
"up_stat", "up_profile", "candidate", "seen_aid", "notify", "fav_action", "kv",
}
@@ -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]
assert current_version(conn) == 3
assert applied == [1, 2, 3, 4]
assert current_version(conn) == 4
assert EXPECTED_TABLES <= table_names(conn)
assert "schema_version" in table_names(conn)
columns = {
@@ -49,10 +49,24 @@ def test_fresh_and_idempotent():
row[1] for row in conn.execute("PRAGMA table_info(candidate)")
}
assert {"duration", "play", "like", "favorite", "danmaku", "review"} <= candidate_columns
video_columns = {
row[1] for row in conn.execute("PRAGMA table_info(video)")
}
assert {
"pages", "duration", "up_follower", "up_follower_at",
"up_follower_backfilled",
} <= video_columns
profile_columns = {
row[1] for row in conn.execute("PRAGMA table_info(up_profile)")
}
assert {
"mid", "follower_first", "following_first", "first_captured_at",
"follower_latest", "last_refreshed",
} <= profile_columns
# 再跑一次不应重复应用
assert run_migrations(conn) == []
row = conn.execute("SELECT COUNT(*) FROM schema_version").fetchone()
assert row[0] == 3
assert row[0] == 4
finally:
conn.close()
@@ -67,15 +81,15 @@ def test_backup_before_upgrade():
conn.execute("INSERT INTO kv(k, v) VALUES ('hello', 'world')")
conn.commit()
v4 = Migration(4, "add probe", ("CREATE TABLE probe (id INTEGER PRIMARY KEY)",))
v5 = Migration(5, "add probe", ("CREATE TABLE probe (id INTEGER PRIMARY KEY)",))
applied = run_migrations(
conn,
backup_dir=backup_dir,
now=1_800_000_000,
migrations=MIGRATIONS + (v4,),
migrations=MIGRATIONS + (v5,),
)
assert applied == [4]
backups = list(backup_dir.glob("app-pre-v3-*.db"))
assert applied == [5]
backups = list(backup_dir.glob("app-pre-v4-*.db"))
assert len(backups) == 1
check = sqlite3.connect(backups[0])
try: