""" Миграция v1.8: добавить поле topic для классификации сообщений """ import sqlite3 import asyncio DB_PATH = 'database/domovoy.db' async def migrate(): """Добавить поле topic в таблицу messages""" conn = sqlite3.connect(DB_PATH) cursor = conn.cursor() # Проверяем есть ли поле topic в messages cursor.execute("PRAGMA table_info(messages)") columns = [col[1] for col in cursor.fetchall()] if 'topic' not in columns: print("➕ Добавляем поле topic...") cursor.execute("ALTER TABLE messages ADD COLUMN topic TEXT") print("✅ Поле topic добавлено") else: print("ℹ️ Поле topic уже существует") # Создаём индекс cursor.execute("CREATE INDEX IF NOT EXISTS ix_messages_topic ON messages(topic)") print("✅ Индекс ix_messages_topic создан") conn.commit() conn.close() print("✅ Миграция v1.8 завершена!") if __name__ == '__main__': asyncio.run(migrate())