feat: /new_creative tg_bot
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
"""add subscription status and unsubscribed_at
|
||||
|
||||
Revision ID: 3b8259700b61
|
||||
Revises: f05f85d10837
|
||||
Create Date: 2025-11-25 18:45:04.642105
|
||||
|
||||
"""
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '3b8259700b61'
|
||||
down_revision: str | None = 'f05f85d10837'
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
# Создаём enum тип явно
|
||||
subscription_status = sa.Enum('ACTIVE', 'UNSUBSCRIBED', name='subscriptionstatus')
|
||||
subscription_status.create(op.get_bind(), checkfirst=True)
|
||||
|
||||
op.add_column(
|
||||
'subscription',
|
||||
sa.Column('status', subscription_status, nullable=False, server_default='ACTIVE'),
|
||||
)
|
||||
op.add_column('subscription', sa.Column('unsubscribed_at', sa.DateTime(timezone=True), nullable=True))
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_column('subscription', 'unsubscribed_at')
|
||||
op.drop_column('subscription', 'status')
|
||||
|
||||
# Удаляем enum тип
|
||||
sa.Enum(name='subscriptionstatus').drop(op.get_bind(), checkfirst=True)
|
||||
# ### end Alembic commands ###
|
||||
@@ -1,63 +0,0 @@
|
||||
"""add unique constraint for active subscriptions
|
||||
|
||||
Revision ID: 52ad7cc9bf1e
|
||||
Revises: 3b8259700b61
|
||||
Create Date: 2025-11-26 14:14:57.814576
|
||||
|
||||
"""
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '52ad7cc9bf1e'
|
||||
down_revision: str | None = '3b8259700b61'
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# Добавляем поле target_channel_id (сначала nullable)
|
||||
op.add_column('subscription', sa.Column('target_channel_id', sa.Uuid(), nullable=True))
|
||||
|
||||
# Заполняем target_channel_id из placement
|
||||
op.execute("""
|
||||
UPDATE subscription
|
||||
SET target_channel_id = placement.target_channel_id
|
||||
FROM placement
|
||||
WHERE subscription.placement_id = placement.id
|
||||
""")
|
||||
|
||||
# Делаем поле NOT NULL после заполнения
|
||||
op.alter_column('subscription', 'target_channel_id', nullable=False)
|
||||
|
||||
# Добавляем FK constraint
|
||||
op.create_foreign_key(
|
||||
'subscription_target_channel_id_fkey', 'subscription', 'target_channel', ['target_channel_id'], ['id']
|
||||
)
|
||||
|
||||
# Создаем индекс на target_channel_id
|
||||
op.create_index(op.f('ix_subscription_target_channel_id'), 'subscription', ['target_channel_id'])
|
||||
|
||||
# Создаём UNIQUE constraint для активных подписок
|
||||
op.create_index(
|
||||
'unique_active_subscription_per_channel',
|
||||
'subscription',
|
||||
['subscriber_id', 'target_channel_id'],
|
||||
unique=True,
|
||||
postgresql_where=sa.text("status = 'ACTIVE'::subscriptionstatus"),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# Удаляем UNIQUE constraint
|
||||
op.drop_index('unique_active_subscription_per_channel', table_name='subscription')
|
||||
|
||||
# Удаляем индекс и FK constraint
|
||||
op.drop_index(op.f('ix_subscription_target_channel_id'), table_name='subscription')
|
||||
op.drop_constraint('subscription_target_channel_id_fkey', 'subscription', type_='foreignkey')
|
||||
|
||||
# Удаляем колонку
|
||||
op.drop_column('subscription', 'target_channel_id')
|
||||
65
migration/versions/b1d510ad3751_.py
Normal file
65
migration/versions/b1d510ad3751_.py
Normal file
@@ -0,0 +1,65 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: b1d510ad3751
|
||||
Revises: f05f85d10837
|
||||
Create Date: 2025-12-01 13:05:17.215374
|
||||
|
||||
"""
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
subscription_status_enum = sa.Enum('ACTIVE', 'UNSUBSCRIBED', name='subscriptionstatus')
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'b1d510ad3751'
|
||||
down_revision: str | None = 'f05f85d10837'
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table(
|
||||
'telegram_state',
|
||||
sa.Column('telegram_id', sa.BigInteger(), nullable=False),
|
||||
sa.Column(
|
||||
'state',
|
||||
sa.Enum(
|
||||
'CREATIVE_WAITING_CHANNEL', 'CREATIVE_WAITING_NAME', 'CREATIVE_WAITING_TEXT', name='telegramstateenum'
|
||||
),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column('context', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
|
||||
sa.Column('id', sa.Uuid(), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
)
|
||||
op.create_index(op.f('ix_telegram_state_telegram_id'), 'telegram_state', ['telegram_id'], unique=True)
|
||||
op.add_column('subscription', sa.Column('target_channel_id', sa.Uuid(), nullable=False))
|
||||
subscription_status_enum.create(op.get_bind(), checkfirst=True)
|
||||
op.add_column('subscription', sa.Column('status', subscription_status_enum, nullable=False))
|
||||
op.add_column('subscription', sa.Column('unsubscribed_at', sa.DateTime(timezone=True), nullable=True))
|
||||
op.create_index(op.f('ix_subscription_target_channel_id'), 'subscription', ['target_channel_id'], unique=False)
|
||||
fk_name = op.f('fk_subscription_target_channel_id')
|
||||
op.create_foreign_key(fk_name, 'subscription', 'target_channel', ['target_channel_id'], ['id'])
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
fk_name = op.f('fk_subscription_target_channel_id')
|
||||
op.drop_constraint(fk_name, 'subscription', type_='foreignkey')
|
||||
op.drop_index(op.f('ix_subscription_target_channel_id'), table_name='subscription')
|
||||
op.drop_column('subscription', 'unsubscribed_at')
|
||||
op.drop_column('subscription', 'status')
|
||||
subscription_status_enum.drop(op.get_bind(), checkfirst=True)
|
||||
op.drop_column('subscription', 'target_channel_id')
|
||||
op.drop_index(op.f('ix_telegram_state_telegram_id'), table_name='telegram_state')
|
||||
op.drop_table('telegram_state')
|
||||
# ### end Alembic commands ###
|
||||
Reference in New Issue
Block a user