feat: track download logs (ip, browser, device, time)

This commit is contained in:
mini
2026-02-18 23:20:50 +08:00
parent 0bab021e21
commit 27c9c87f5c
5 changed files with 149 additions and 15 deletions

View File

@@ -21,9 +21,14 @@ async def get_db():
async def init_db():
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
# Ensure composite index exists on already-created tables (idempotent)
await conn.execute(
__import__("sqlalchemy").text(
"CREATE INDEX IF NOT EXISTS ix_video_url_format_id ON videos (url, format_id)"
)
)
# Ensure indexes exist on already-created tables (idempotent)
from sqlalchemy import text
await conn.execute(text(
"CREATE INDEX IF NOT EXISTS ix_video_url_format_id ON videos (url, format_id)"
))
await conn.execute(text(
"CREATE INDEX IF NOT EXISTS ix_download_logs_video_id ON download_logs (video_id)"
))
await conn.execute(text(
"CREATE INDEX IF NOT EXISTS ix_download_logs_downloaded_at ON download_logs (downloaded_at)"
))