feat(stats): add migration v7 visit table and client-ip helpers
This commit is contained in:
1 parent
b0c53e8a2f
commit
cdd11823b9
8 files changed
+531
-15
No files matched your search
@@ -22,6 +22,7 @@ from reaction_board.migrations import ( # noqa: E402
|
||||
EXPECTED_TABLES = {
|
||||
"video", "snapshot", "folder", "folder_resource", "up_blacklist",
|
||||
"up_stat", "up_profile", "candidate", "seen_aid", "notify", "fav_action", "kv",
|
||||
"visit",
|
||||
}
|
||||
|
||||
|
||||
@@ -37,8 +38,8 @@ def test_fresh_and_idempotent():
|
||||
conn = sqlite3.connect(Path(tmp) / "app.db")
|
||||
try:
|
||||
applied = run_migrations(conn)
|
||||
assert applied == [1, 2, 3, 4, 5, 6]
|
||||
assert current_version(conn) == 6
|
||||
assert applied == [1, 2, 3, 4, 5, 6, 7]
|
||||
assert current_version(conn) == 7
|
||||
assert EXPECTED_TABLES <= table_names(conn)
|
||||
assert "schema_version" in table_names(conn)
|
||||
columns = {
|
||||
@@ -63,10 +64,16 @@ def test_fresh_and_idempotent():
|
||||
"mid", "follower_first", "following_first", "first_captured_at",
|
||||
"follower_latest", "last_refreshed",
|
||||
} <= profile_columns
|
||||
visit_columns = {
|
||||
row[1] for row in conn.execute("PRAGMA table_info(visit)")
|
||||
}
|
||||
assert {
|
||||
"stat_date", "ip", "path", "hits", "first_at", "last_at",
|
||||
} <= visit_columns
|
||||
# 再跑一次不应重复应用
|
||||
assert run_migrations(conn) == []
|
||||
row = conn.execute("SELECT COUNT(*) FROM schema_version").fetchone()
|
||||
assert row[0] == 6
|
||||
assert row[0] == 7
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
@@ -81,15 +88,15 @@ def test_backup_before_upgrade():
|
||||
conn.execute("INSERT INTO kv(k, v) VALUES ('hello', 'world')")
|
||||
conn.commit()
|
||||
|
||||
v7 = Migration(7, "add probe", ("CREATE TABLE probe (id INTEGER PRIMARY KEY)",))
|
||||
v8 = Migration(8, "add probe", ("CREATE TABLE probe (id INTEGER PRIMARY KEY)",))
|
||||
applied = run_migrations(
|
||||
conn,
|
||||
backup_dir=backup_dir,
|
||||
now=1_800_000_000,
|
||||
migrations=MIGRATIONS + (v7,),
|
||||
migrations=MIGRATIONS + (v8,),
|
||||
)
|
||||
assert applied == [7]
|
||||
backups = list(backup_dir.glob("app-pre-v6-*.db"))
|
||||
assert applied == [8]
|
||||
backups = list(backup_dir.glob("app-pre-v7-*.db"))
|
||||
assert len(backups) == 1
|
||||
check = sqlite3.connect(backups[0])
|
||||
try:
|
||||
@@ -174,7 +181,7 @@ def test_v5_normalizes_unfaved():
|
||||
)
|
||||
conn.commit()
|
||||
applied = run_migrations(conn)
|
||||
assert applied == [5, 6]
|
||||
assert applied == [5, 6, 7]
|
||||
rows = dict(conn.execute("SELECT aid, status FROM video").fetchall())
|
||||
assert rows == {1: "active", 2: "dropped"}
|
||||
finally:
|
||||
|
||||
Reference in new issue
Block a user