domovoy_bot/database/migrate_v3_1_smart_broadcasts.py
Admin 222c2ba521 🚀 feat: V3.1 - Smart broadcasts with read tracking + Weekly digests with approval workflow
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-04-06 23:01:10 +04:00

51 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

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.

"""
Миграция: Добавление таблиц для умных рассылок и дайджестов
Версия: V3.1
Дата: 2026-04-06
Новые таблицы:
- broadcasts: умные рассылки с отслеживанием прочтения
- broadcast_reads: кто прочитал рассылку
- digests: еженедельные дайджесты
"""
import sys
import os
# Добавляем корень проекта в path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from database.db import SyncSessionLocal, sync_engine
from database.models import Base
from sqlalchemy import inspect
def migrate():
"""Выполнить миграцию"""
print("🔧 Начинаем миграцию V3.1...")
inspector = inspect(sync_engine)
existing_tables = inspector.get_table_names()
print(f"📋 Текущие таблицы: {len(existing_tables)}")
# Создаём новые таблицы
new_tables = ['broadcasts', 'broadcast_reads', 'digests']
for table_name in new_tables:
if table_name in existing_tables:
print(f"⏭️ Таблица '{table_name}' уже существует, пропускаем")
else:
print(f"✅ Создаём таблицу '{table_name}'...")
# Создаём только конкретные таблицы
Base.metadata.tables[table_name].create(bind=sync_engine)
print(f" ✓ Таблица '{table_name}' создана")
print("\n✅ Миграция V3.1 завершена успешно!")
print("📊 Новые таблицы:")
print(" • broadcasts - умные рассылки")
print(" • broadcast_reads - отслеживание прочтения")
print(" • digests - еженедельные дайджесты")
if __name__ == '__main__':
migrate()