domovoy_bot/database/migrate_add_initiative_group.py
Admin 19c5fdd0ac feat: v2.1 - Инициативная группа
 Модель InitiativeGroup в БД
 Сервис initiative_group.py
 Хендлеры: /ig_add, /ig_remove, /ig_list, /ig_stats, /ig_check, /ig_broadcast
 Декораторы для ИГ
 Миграция v2.1 выполнена

📦 Бекап: backups/versions/v2.1_initiative_group_2026-02-27/

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-02-28 10:11:36 +00:00

49 lines
1.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.

"""
Миграция v2.1: создать таблицу initiative_group для инициативной группы
"""
import sqlite3
import asyncio
DB_PATH = 'database/domovoy.db'
async def migrate():
"""Создать таблицу initiative_group"""
conn = sqlite3.connect(DB_PATH)
cursor = conn.cursor()
# Проверяем, есть ли уже таблица initiative_group
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='initiative_group'")
existing = cursor.fetchone()
if existing:
print(" Таблица initiative_group уже существует")
else:
print(" Создаём таблицу initiative_group...")
cursor.execute("""
CREATE TABLE initiative_group (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id BIGINT NOT NULL UNIQUE,
role TEXT DEFAULT 'member',
joined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
is_active BOOLEAN DEFAULT 1,
notes TEXT,
FOREIGN KEY (user_id) REFERENCES users(user_id)
)
""")
# Создаём индексы
cursor.execute("CREATE INDEX ix_initiative_group_user ON initiative_group(user_id)")
cursor.execute("CREATE INDEX ix_initiative_group_active ON initiative_group(is_active)")
print("✅ Таблица initiative_group создана")
print("✅ Индексы созданы")
conn.commit()
conn.close()
print("✅ Миграция v2.1 завершена!")
if __name__ == '__main__':
asyncio.run(migrate())