Первый коммит

This commit is contained in:
2026-02-17 11:24:55 +07:00
commit a06448ca4b
109 changed files with 21165 additions and 0 deletions

51
database/migrate.py Normal file
View File

@@ -0,0 +1,51 @@
# Создайте файл database/migrate.py
"""
Миграция: добавление полей matched_word и match_type в SpamLog
"""
import asyncio
from sqlalchemy import text
from .manager import get_manager
async def migrate():
"""Добавляет поля matched_word и match_type если их нет"""
manager = get_manager()
await manager.init()
async with manager.session_maker() as session:
try:
# Проверяем наличие колонок
result = await session.execute(
text("PRAGMA table_info(spam_logs)")
)
columns = [row[1] for row in result.fetchall()]
if 'matched_word' not in columns:
print("Добавляем колонку matched_word...")
await session.execute(
text("ALTER TABLE spam_logs ADD COLUMN matched_word VARCHAR(255)")
)
await session.commit()
print("✅ Колонка matched_word добавлена")
if 'match_type' not in columns:
print("Добавляем колонку match_type...")
await session.execute(
text("ALTER TABLE spam_logs ADD COLUMN match_type VARCHAR(50)")
)
await session.commit()
print("✅ Колонка match_type добавлена")
print("✅ Миграция завершена успешно!")
except Exception as e:
print(f"❌ Ошибка миграции: {e}")
await session.rollback()
finally:
await manager.close()
if __name__ == "__main__":
asyncio.run(migrate())