domovoy_bot/database/migrate_add_polls.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

53 lines
1.7 KiB
Python
Raw 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.1: создать таблицу polls для опросов
"""
import sqlite3
import asyncio
DB_PATH = 'database/domovoy.db'
async def migrate():
"""Создать таблицу polls"""
conn = sqlite3.connect(DB_PATH)
cursor = conn.cursor()
# Проверяем, есть ли уже таблица polls
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='polls'")
existing = cursor.fetchone()
if existing:
print(" Таблица polls уже существует")
else:
print(" Создаём таблицу polls...")
cursor.execute("""
CREATE TABLE polls (
poll_id INTEGER PRIMARY KEY AUTOINCREMENT,
message_id BIGINT NOT NULL,
chat_id BIGINT NOT NULL,
question TEXT NOT NULL,
options TEXT NOT NULL,
votes TEXT,
created_by BIGINT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
is_active BOOLEAN DEFAULT 1,
closed_at TIMESTAMP,
FOREIGN KEY (created_by) REFERENCES users(user_id)
)
""")
# Создаём индексы
cursor.execute("CREATE INDEX ix_polls_chat_active ON polls(chat_id, is_active)")
cursor.execute("CREATE INDEX ix_polls_created_at ON polls(created_at)")
print("✅ Таблица polls создана")
print("✅ Индексы созданы")
conn.commit()
conn.close()
print("✅ Миграция v1.1 завершена!")
if __name__ == '__main__':
asyncio.run(migrate())