""" Миграция v1.13: создать таблицу thanks для благодарностей пользователей """ import sqlite3 import asyncio DB_PATH = 'database/domovoy.db' async def migrate(): """Создать таблицу thanks""" conn = sqlite3.connect(DB_PATH) cursor = conn.cursor() # Проверяем, есть ли уже таблица thanks cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='thanks'") existing = cursor.fetchone() if existing: print("ℹ️ Таблица thanks уже существует") else: print("➕ Создаём таблицу thanks...") cursor.execute(""" CREATE TABLE thanks ( id INTEGER PRIMARY KEY AUTOINCREMENT, from_user_id BIGINT NOT NULL, to_user_id BIGINT NOT NULL, message TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (from_user_id) REFERENCES users(user_id), FOREIGN KEY (to_user_id) REFERENCES users(user_id) ) """) # Создаём индексы cursor.execute("CREATE INDEX ix_thanks_from ON thanks(from_user_id)") cursor.execute("CREATE INDEX ix_thanks_to ON thanks(to_user_id)") cursor.execute("CREATE INDEX ix_thanks_created ON thanks(created_at)") print("✅ Таблица thanks создана") print("✅ Индексы созданы") conn.commit() conn.close() print("✅ Миграция v1.13 завершена!") if __name__ == '__main__': asyncio.run(migrate())