domovoy_bot/database/migrate_add_rate_limits.py
Admin ba4676b0af v1.0 MVP - Инициализация проекта 🏠
 Регистрация и верификация жильцов
 Рейтинг активности (уровни)
 Детект шпионов (Score 0-100)
 Анти-мат система (3 предупреждения → бан)
 Админ-панель с рассылкой
 Учёт квартир (несколько жильцов)
 Телефоны экстренных служб и мастеров
 Еженедельный экспорт JSON
 Прокси (socks5) для обхода РКН

Бекап: backups/versions/v1.0_mvp_2026-02-26/

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-02-27 10:54:16 +00:00

71 lines
2.7 KiB
Python
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
Миграция v1.3: создать таблицу message_rates для анти-спама лимитов
"""
import sqlite3
import asyncio
DB_PATH = 'database/domovoy.db'
async def migrate():
"""Создать таблицу message_rates и добавить поля в users"""
conn = sqlite3.connect(DB_PATH)
cursor = conn.cursor()
# Проверяем, есть ли уже таблица message_rates
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='message_rates'")
existing = cursor.fetchone()
if existing:
print(" Таблица message_rates уже существует")
else:
print(" Создаём таблицу message_rates...")
cursor.execute("""
CREATE TABLE message_rates (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id BIGINT NOT NULL,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(user_id)
)
""")
# Создаём индексы
cursor.execute("CREATE INDEX ix_message_rates_user ON message_rates(user_id)")
cursor.execute("CREATE INDEX ix_message_rates_time ON message_rates(timestamp)")
print("✅ Таблица message_rates создана")
print("✅ Индексы созданы")
# Проверяем есть ли поля в users
cursor.execute("PRAGMA table_info(users)")
columns = [col[1] for col in cursor.fetchall()]
if 'is_muted' not in columns:
print(" Добавляем поле is_muted...")
cursor.execute("ALTER TABLE users ADD COLUMN is_muted BOOLEAN DEFAULT 0")
print("✅ Поле is_muted добавлено")
else:
print(" Поле is_muted уже существует")
if 'mute_until' not in columns:
print(" Добавляем поле mute_until...")
cursor.execute("ALTER TABLE users ADD COLUMN mute_until TIMESTAMP")
print("✅ Поле mute_until добавлено")
else:
print(" Поле mute_until уже существует")
if 'rate_limit_warnings' not in columns:
print(" Добавляем поле rate_limit_warnings...")
cursor.execute("ALTER TABLE users ADD COLUMN rate_limit_warnings INTEGER DEFAULT 0")
print("✅ Поле rate_limit_warnings добавлено")
else:
print(" Поле rate_limit_warnings уже существует")
conn.commit()
conn.close()
print("✅ Миграция v1.3 завершена!")
if __name__ == '__main__':
asyncio.run(migrate())