From 365f75447f035b4789a8b82c0cb7d6c2431d1178 Mon Sep 17 00:00:00 2001 From: Egor Date: Sat, 31 Jan 2026 18:12:53 +0300 Subject: [PATCH 1/2] Update universal_migration.py --- app/database/universal_migration.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/database/universal_migration.py b/app/database/universal_migration.py index a6c72f2e..39a9b05a 100644 --- a/app/database/universal_migration.py +++ b/app/database/universal_migration.py @@ -3369,6 +3369,9 @@ async def add_email_fields_to_broadcast_history(): try: async with engine.begin() as conn: + db_type = await get_database_type() + + # Добавление новых полей for field_name, field_type in email_fields.items(): field_exists = await check_column_exists('broadcast_history', field_name) @@ -3381,6 +3384,23 @@ async def add_email_fields_to_broadcast_history(): else: logger.info(f'Поле {field_name} уже существует в broadcast_history') + # Сделать message_text nullable для email-only рассылок + try: + if db_type == 'postgresql': + await conn.execute( + text('ALTER TABLE broadcast_history ALTER COLUMN message_text DROP NOT NULL') + ) + logger.info('✅ Колонка message_text теперь nullable') + elif db_type == 'mysql': + await conn.execute( + text('ALTER TABLE broadcast_history MODIFY COLUMN message_text TEXT NULL') + ) + logger.info('✅ Колонка message_text теперь nullable') + # SQLite не поддерживает ALTER COLUMN, но там по умолчанию nullable + except Exception as e: + # Игнорируем если уже nullable или другая ошибка + logger.debug(f'message_text nullable: {e}') + logger.info('✅ Все поля email в broadcast_history готовы') return True From 1092301767248212aafd44f33e191452a7f4b095 Mon Sep 17 00:00:00 2001 From: Egor Date: Sat, 31 Jan 2026 18:13:42 +0300 Subject: [PATCH 2/2] Update universal_migration.py --- app/database/universal_migration.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/database/universal_migration.py b/app/database/universal_migration.py index 39a9b05a..c97dddff 100644 --- a/app/database/universal_migration.py +++ b/app/database/universal_migration.py @@ -3387,14 +3387,10 @@ async def add_email_fields_to_broadcast_history(): # Сделать message_text nullable для email-only рассылок try: if db_type == 'postgresql': - await conn.execute( - text('ALTER TABLE broadcast_history ALTER COLUMN message_text DROP NOT NULL') - ) + await conn.execute(text('ALTER TABLE broadcast_history ALTER COLUMN message_text DROP NOT NULL')) logger.info('✅ Колонка message_text теперь nullable') elif db_type == 'mysql': - await conn.execute( - text('ALTER TABLE broadcast_history MODIFY COLUMN message_text TEXT NULL') - ) + await conn.execute(text('ALTER TABLE broadcast_history MODIFY COLUMN message_text TEXT NULL')) logger.info('✅ Колонка message_text теперь nullable') # SQLite не поддерживает ALTER COLUMN, но там по умолчанию nullable except Exception as e: