Move to hour-resolution adverts

This commit is contained in:
Jack Kingsman
2026-02-23 16:34:34 -08:00
parent 88d5a76081
commit ef4c79bc80
6 changed files with 90 additions and 31 deletions
+31
View File
@@ -177,6 +177,13 @@ async def run_migrations(conn: aiosqlite.Connection) -> int:
await set_version(conn, 20)
applied += 1
# Migration 21: Enforce minimum 1-hour advert interval
if version < 21:
logger.info("Applying migration 21: enforce minimum 1-hour advert interval")
await _migrate_021_enforce_min_advert_interval(conn)
await set_version(conn, 21)
applied += 1
if applied > 0:
logger.info(
"Applied %d migration(s), schema now at version %d", applied, await get_version(conn)
@@ -1252,3 +1259,27 @@ async def _migrate_020_enable_wal_and_auto_vacuum(conn: aiosqlite.Connection) ->
logger.info("Journal mode set to %s", mode)
await conn.commit()
async def _migrate_021_enforce_min_advert_interval(conn: aiosqlite.Connection) -> None:
"""
Enforce minimum 1-hour advert interval.
Any advert_interval between 1 and 3599 is clamped up to 3600 (1 hour).
Zero (disabled) is left unchanged.
"""
# Guard: app_settings table may not exist if running against a very old schema
# (it's created in migration 9). The UPDATE is harmless if the table exists
# but has no rows, but will error if the table itself is missing.
cursor = await conn.execute(
"SELECT name FROM sqlite_master WHERE type='table' AND name='app_settings'"
)
if await cursor.fetchone() is None:
logger.debug("app_settings table does not exist yet, skipping advert_interval clamp")
return
await conn.execute(
"UPDATE app_settings SET advert_interval = 3600 WHERE advert_interval > 0 AND advert_interval < 3600"
)
await conn.commit()
logger.debug("Clamped advert_interval to minimum 3600 seconds")