domovoy_bot/database/migrate_add_scheduled_posts.py
Admin fc06ec4a12 v1.3 - Scheduled Posts: отложенная публикация постов по расписанию
- Новая страница /scheduled_posts в веб-панели
- Создание постов с фото/текстом в любую тему форума
- Планирование даты и времени публикации
- Автоматическая отправка по расписанию (каждую минуту)
- Поддержка всех 10 тем форума
- Уведомления админа о публикации/ошибках
- Миграция БД: таблица scheduled_posts
- Тесты: test_scheduled_posts.py

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-04-05 15:52:47 +04:00

48 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.

"""
Миграция: Добавить таблицу scheduled_posts для отложенной публикации
"""
import sqlite3
DB_PATH = 'database/domovoy.db'
def migrate():
"""Создать таблицу scheduled_posts"""
conn = sqlite3.connect(DB_PATH)
cursor = conn.cursor()
# Проверяем таблицу
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='scheduled_posts'")
if not cursor.fetchone():
print(" Создаём таблицу scheduled_posts...")
cursor.execute("""
CREATE TABLE scheduled_posts (
id INTEGER PRIMARY KEY AUTOINCREMENT,
text TEXT NOT NULL,
photo_file_id TEXT,
topic_id BIGINT,
topic_name TEXT,
recipients TEXT DEFAULT 'chat_only',
scheduled_time TIMESTAMP NOT NULL,
status TEXT DEFAULT 'pending',
created_by BIGINT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
sent_at TIMESTAMP,
error_message TEXT,
message_id BIGINT,
FOREIGN KEY (created_by) REFERENCES users(user_id)
)
""")
cursor.execute("CREATE INDEX ix_scheduled_posts_time ON scheduled_posts(scheduled_time)")
cursor.execute("CREATE INDEX ix_scheduled_posts_status ON scheduled_posts(status)")
cursor.execute("CREATE INDEX ix_scheduled_posts_topic ON scheduled_posts(topic_name)")
conn.commit()
print("✅ Таблица scheduled_posts создана")
else:
print(" Таблица scheduled_posts уже существует")
conn.close()
if __name__ == '__main__':
migrate()