"""Bot-owned migrations on real temporary SQLite files, never production DBs.""" import sqlite3 import time import pytest import bot_schema # Literal legacy contract, deliberately independent of the migration's own list. EXPECTED_USER_COLUMNS = set(""" tg_id username token_name api_key created notified points referred_by ref_time ref_awarded lang menu_style chat_mode waiting_prompt chat_count img_count quota_date chat_model img_model vip last_checkin last_loyalty admin captcha_ok banned week_model week_key last_active warned_at ref_credit key_locked rep quiz_last dice_last last_bonus_lvl rep_last badge_lock last_bonus_ts rank_cache ref_notify vid_model mus_model sub_penalized rep_give_day rep_give_n api_blocked api_block_reason gate_member_ok gate_member_ts gate_warned_at agent_model effort prompt_on badge_until """.split()) def test_fresh_database_has_complete_versioned_schema_and_indexed_hot_paths(tmp_path): path = tmp_path / "bot.db" bot_schema.initialize_bot_db(path) with sqlite3.connect(path) as con: assert con.execute("PRAGMA user_version").fetchone()[0] == bot_schema.SCHEMA_VERSION columns = {row[1] for row in con.execute("PRAGMA table_info(users)")} assert columns == EXPECTED_USER_COLUMNS queries = [ ("SELECT COUNT(*) FROM group_log WHERE uid=? AND ts>=?", (1, 0)), ("SELECT DISTINCT uid FROM group_log WHERE chat_id=? AND ts>?", (1, 0)), ("DELETE FROM group_log WHERE ts