""" Миграция v1.4: создать таблицу schedules для расписания отключений """ import sqlite3 import asyncio DB_PATH = 'database/domovoy.db' async def migrate(): """Создать таблицу schedules""" conn = sqlite3.connect(DB_PATH) cursor = conn.cursor() # Проверяем, есть ли уже таблица schedules cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='schedules'") existing = cursor.fetchone() if existing: print("ℹ️ Таблица schedules уже существует") else: print("➕ Создаём таблицу schedules...") cursor.execute(""" CREATE TABLE schedules ( schedule_id INTEGER PRIMARY KEY AUTOINCREMENT, schedule_type TEXT NOT NULL, title TEXT NOT NULL, description TEXT, start_time TIMESTAMP NOT NULL, end_time TIMESTAMP NOT NULL, created_by BIGINT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, reminder_sent BOOLEAN DEFAULT 0, is_active BOOLEAN DEFAULT 1, FOREIGN KEY (created_by) REFERENCES users(user_id) ) """) # Создаём индексы cursor.execute("CREATE INDEX ix_schedules_type ON schedules(schedule_type)") cursor.execute("CREATE INDEX ix_schedules_time ON schedules(start_time, end_time)") cursor.execute("CREATE INDEX ix_schedules_active ON schedules(is_active)") print("✅ Таблица schedules создана") print("✅ Индексы созданы") conn.commit() conn.close() print("✅ Миграция v1.4 завершена!") if __name__ == '__main__': asyncio.run(migrate())