"""init Revision ID: f05f85d10837 Revises: Create Date: 2025-11-13 01:06:51.623272 """ from typing import Sequence, Union from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. revision: str = 'f05f85d10837' down_revision: Union[str, None] = None branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### op.create_table('subscriber', sa.Column('telegram_id', sa.BigInteger(), nullable=False), sa.Column('username', sa.String(), nullable=True), sa.Column('first_name', sa.String(), nullable=True), sa.Column('last_name', sa.String(), nullable=True), 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_subscriber_telegram_id'), 'subscriber', ['telegram_id'], unique=True) op.create_table('user', sa.Column('telegram_id', sa.Integer(), nullable=False), sa.Column('username', sa.String(), nullable=True), 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_user_telegram_id'), 'user', ['telegram_id'], unique=True) op.create_table('external_channel', sa.Column('telegram_id', sa.BigInteger(), nullable=False), sa.Column('title', sa.String(), nullable=False), sa.Column('username', sa.String(), nullable=True), sa.Column('description', sa.String(), nullable=True), sa.Column('subscribers_count', sa.Integer(), nullable=True), sa.Column('user_id', sa.Uuid(), 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.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_external_channel_telegram_id'), 'external_channel', ['telegram_id'], unique=True) op.create_index(op.f('ix_external_channel_user_id'), 'external_channel', ['user_id'], unique=False) op.create_index(op.f('ix_external_channel_username'), 'external_channel', ['username'], unique=False) op.create_table('login_token', sa.Column('token', sa.String(), nullable=False), sa.Column('user_id', sa.Uuid(), nullable=False), sa.Column('expires_at', sa.DateTime(timezone=True), nullable=False), sa.Column('used_at', sa.DateTime(timezone=True), nullable=True), 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.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_login_token_token'), 'login_token', ['token'], unique=True) op.create_table('target_channel', sa.Column('telegram_id', sa.BigInteger(), nullable=False), sa.Column('title', sa.String(), nullable=False), sa.Column('username', sa.String(), nullable=True), sa.Column('status', sa.Enum('ACTIVE', 'INACTIVE', 'ARCHIVED', name='targetchannelstatus'), nullable=False), sa.Column('user_id', sa.Uuid(), 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.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_target_channel_telegram_id'), 'target_channel', ['telegram_id'], unique=True) op.create_index(op.f('ix_target_channel_user_id'), 'target_channel', ['user_id'], unique=False) op.create_index(op.f('ix_target_channel_username'), 'target_channel', ['username'], unique=False) op.create_table('creative', sa.Column('name', sa.String(), nullable=False), sa.Column('text', sa.String(), nullable=False), sa.Column('status', sa.Enum('ACTIVE', 'ARCHIVED', name='creativestatus'), nullable=False), sa.Column('placements_count', sa.Integer(), server_default='0', nullable=False), sa.Column('user_id', sa.Uuid(), nullable=False), sa.Column('target_channel_id', sa.Uuid(), 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.ForeignKeyConstraint(['target_channel_id'], ['target_channel.id'], ), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_creative_target_channel_id'), 'creative', ['target_channel_id'], unique=False) op.create_index(op.f('ix_creative_user_id'), 'creative', ['user_id'], unique=False) op.create_table('target_external_channel', sa.Column('target_channel_id', sa.Uuid(), nullable=False), sa.Column('external_channel_id', sa.Uuid(), nullable=False), sa.ForeignKeyConstraint(['external_channel_id'], ['external_channel.id'], ondelete='CASCADE'), sa.ForeignKeyConstraint(['target_channel_id'], ['target_channel.id'], ondelete='CASCADE'), sa.PrimaryKeyConstraint('target_channel_id', 'external_channel_id') ) op.create_table('placement', sa.Column('target_channel_id', sa.Uuid(), nullable=False), sa.Column('external_channel_id', sa.Uuid(), nullable=False), sa.Column('creative_id', sa.Uuid(), nullable=False), sa.Column('user_id', sa.Uuid(), nullable=False), sa.Column('placement_date', sa.DateTime(timezone=True), nullable=False), sa.Column('cost', sa.Float(), nullable=True), sa.Column('comment', sa.String(), nullable=True), sa.Column('ad_post_url', sa.String(), nullable=True), sa.Column('invite_link_type', sa.Enum('PUBLIC', 'APPROVAL', name='invitelinktype'), nullable=False), sa.Column('invite_link', sa.String(), nullable=False), sa.Column('status', sa.Enum('ACTIVE', 'ARCHIVED', name='placementstatus'), nullable=False), sa.Column('subscriptions_count', sa.Integer(), server_default='0', nullable=False), sa.Column('views_count', sa.Integer(), nullable=True), sa.Column('views_availability', sa.Enum('UNKNOWN', 'AVAILABLE', 'UNAVAILABLE', 'MANUAL', name='postviewsavailability'), nullable=False), sa.Column('last_views_fetch_at', sa.DateTime(timezone=True), nullable=True), 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.ForeignKeyConstraint(['creative_id'], ['creative.id'], ), sa.ForeignKeyConstraint(['external_channel_id'], ['external_channel.id'], ), sa.ForeignKeyConstraint(['target_channel_id'], ['target_channel.id'], ), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_placement_creative_id'), 'placement', ['creative_id'], unique=False) op.create_index(op.f('ix_placement_external_channel_id'), 'placement', ['external_channel_id'], unique=False) op.create_index(op.f('ix_placement_target_channel_id'), 'placement', ['target_channel_id'], unique=False) op.create_index(op.f('ix_placement_user_id'), 'placement', ['user_id'], unique=False) op.create_table('placement_views_history', sa.Column('placement_id', sa.Uuid(), nullable=False), sa.Column('views_count', sa.Integer(), nullable=False), sa.Column('fetched_at', sa.DateTime(timezone=True), 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.ForeignKeyConstraint(['placement_id'], ['placement.id'], ), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_placement_views_history_fetched_at'), 'placement_views_history', ['fetched_at'], unique=False) op.create_index(op.f('ix_placement_views_history_placement_id'), 'placement_views_history', ['placement_id'], unique=False) op.create_table('subscription', sa.Column('placement_id', sa.Uuid(), nullable=False), sa.Column('subscriber_id', sa.Uuid(), nullable=False), sa.Column('invite_link', sa.String(), 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.ForeignKeyConstraint(['placement_id'], ['placement.id'], ), sa.ForeignKeyConstraint(['subscriber_id'], ['subscriber.id'], ), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_subscription_invite_link'), 'subscription', ['invite_link'], unique=False) op.create_index(op.f('ix_subscription_placement_id'), 'subscription', ['placement_id'], unique=False) op.create_index(op.f('ix_subscription_subscriber_id'), 'subscription', ['subscriber_id'], unique=False) # ### end Alembic commands ### def downgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### op.drop_index(op.f('ix_subscription_subscriber_id'), table_name='subscription') op.drop_index(op.f('ix_subscription_placement_id'), table_name='subscription') op.drop_index(op.f('ix_subscription_invite_link'), table_name='subscription') op.drop_table('subscription') op.drop_index(op.f('ix_placement_views_history_placement_id'), table_name='placement_views_history') op.drop_index(op.f('ix_placement_views_history_fetched_at'), table_name='placement_views_history') op.drop_table('placement_views_history') op.drop_index(op.f('ix_placement_user_id'), table_name='placement') op.drop_index(op.f('ix_placement_target_channel_id'), table_name='placement') op.drop_index(op.f('ix_placement_external_channel_id'), table_name='placement') op.drop_index(op.f('ix_placement_creative_id'), table_name='placement') op.drop_table('placement') op.drop_table('target_external_channel') op.drop_index(op.f('ix_creative_user_id'), table_name='creative') op.drop_index(op.f('ix_creative_target_channel_id'), table_name='creative') op.drop_table('creative') op.drop_index(op.f('ix_target_channel_username'), table_name='target_channel') op.drop_index(op.f('ix_target_channel_user_id'), table_name='target_channel') op.drop_index(op.f('ix_target_channel_telegram_id'), table_name='target_channel') op.drop_table('target_channel') op.drop_index(op.f('ix_login_token_token'), table_name='login_token') op.drop_table('login_token') op.drop_index(op.f('ix_external_channel_username'), table_name='external_channel') op.drop_index(op.f('ix_external_channel_user_id'), table_name='external_channel') op.drop_index(op.f('ix_external_channel_telegram_id'), table_name='external_channel') op.drop_table('external_channel') op.drop_index(op.f('ix_user_telegram_id'), table_name='user') op.drop_table('user') op.drop_index(op.f('ix_subscriber_telegram_id'), table_name='subscriber') op.drop_table('subscriber') # ### end Alembic commands ###