66 lines
2.9 KiB
Python
66 lines
2.9 KiB
Python
"""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 ###
|