from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

revision = '0334_broadcast_message_number'
down_revision = '0333_service_broadcast_provider'


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.execute("create sequence broadcast_provider_message_number_seq")
    op.create_table(
        'broadcast_provider_message_number',
        sa.Column(
            'broadcast_provider_message_number',
            sa.Integer(),
            server_default=sa.text("nextval('broadcast_provider_message_number_seq')"),
            nullable=False
        ),
        sa.Column('broadcast_provider_message_id', postgresql.UUID(as_uuid=True), nullable=False),
        sa.ForeignKeyConstraint(['broadcast_provider_message_id'], ['broadcast_provider_message.id'], ),
        sa.PrimaryKeyConstraint('broadcast_provider_message_number')
    )
    op.execute(
        """
            INSERT INTO
                broadcast_provider_message_number (broadcast_provider_message_id)
            SELECT
                id
            FROM
                broadcast_provider_message
        """
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('broadcast_provider_message_number')
    op.execute("drop sequence broadcast_provider_message_number_seq")
    # ### end Alembic commands ###

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

revision = '0334_broadcast_message_number'
down_revision = '0333_service_broadcast_provider'


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.execute("create sequence broadcast_provider_message_number_seq")
    op.create_table(
        'broadcast_provider_message_number',
        sa.Column(
            'broadcast_provider_message_number',
            sa.Integer(),
            server_default=sa.text("nextval('broadcast_provider_message_number_seq')"),
            nullable=False
        ),
        sa.Column('broadcast_provider_message_id', postgresql.UUID(as_uuid=True), nullable=False),
        sa.ForeignKeyConstraint(['broadcast_provider_message_id'], ['broadcast_provider_message.id'], ),
        sa.PrimaryKeyConstraint('broadcast_provider_message_number')
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('broadcast_provider_message_number')
    op.execute("drop sequence broadcast_provider_message_number_seq")
    # ### end Alembic commands ###

Delete unneeded code form migration
Delete unneeded code form migration

  from alembic import op
  import sqlalchemy as sa
  from sqlalchemy.dialects import postgresql
  
  revision = '0334_broadcast_message_number'
  down_revision = '0333_service_broadcast_provider'
  
  
  def upgrade():
      # ### commands auto generated by Alembic - please adjust! ###
      op.execute("create sequence broadcast_provider_message_number_seq")
      op.create_table(
          'broadcast_provider_message_number',
          sa.Column(
              'broadcast_provider_message_number',
              sa.Integer(),
              server_default=sa.text("nextval('broadcast_provider_message_number_seq')"),
              nullable=False
          ),
          sa.Column('broadcast_provider_message_id', postgresql.UUID(as_uuid=True), nullable=False),
          sa.ForeignKeyConstraint(['broadcast_provider_message_id'], ['broadcast_provider_message.id'], ),
          sa.PrimaryKeyConstraint('broadcast_provider_message_number')
      )
-     op.execute(
-         """
-             INSERT INTO
-                 broadcast_provider_message_number (broadcast_provider_message_id)
-             SELECT
-                 id
-             FROM
-                 broadcast_provider_message
-         """
-     )
      # ### end Alembic commands ###
  
  
  def downgrade():
      # ### commands auto generated by Alembic - please adjust! ###
      op.drop_table('broadcast_provider_message_number')
      op.execute("drop sequence broadcast_provider_message_number_seq")
      # ### end Alembic commands ###
  
Delete unneeded code form migration
## Code Before:
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

revision = '0334_broadcast_message_number'
down_revision = '0333_service_broadcast_provider'


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.execute("create sequence broadcast_provider_message_number_seq")
    op.create_table(
        'broadcast_provider_message_number',
        sa.Column(
            'broadcast_provider_message_number',
            sa.Integer(),
            server_default=sa.text("nextval('broadcast_provider_message_number_seq')"),
            nullable=False
        ),
        sa.Column('broadcast_provider_message_id', postgresql.UUID(as_uuid=True), nullable=False),
        sa.ForeignKeyConstraint(['broadcast_provider_message_id'], ['broadcast_provider_message.id'], ),
        sa.PrimaryKeyConstraint('broadcast_provider_message_number')
    )
    op.execute(
        """
            INSERT INTO
                broadcast_provider_message_number (broadcast_provider_message_id)
            SELECT
                id
            FROM
                broadcast_provider_message
        """
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('broadcast_provider_message_number')
    op.execute("drop sequence broadcast_provider_message_number_seq")
    # ### end Alembic commands ###

## Instruction:
Delete unneeded code form migration
## Code After:
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

revision = '0334_broadcast_message_number'
down_revision = '0333_service_broadcast_provider'


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.execute("create sequence broadcast_provider_message_number_seq")
    op.create_table(
        'broadcast_provider_message_number',
        sa.Column(
            'broadcast_provider_message_number',
            sa.Integer(),
            server_default=sa.text("nextval('broadcast_provider_message_number_seq')"),
            nullable=False
        ),
        sa.Column('broadcast_provider_message_id', postgresql.UUID(as_uuid=True), nullable=False),
        sa.ForeignKeyConstraint(['broadcast_provider_message_id'], ['broadcast_provider_message.id'], ),
        sa.PrimaryKeyConstraint('broadcast_provider_message_number')
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('broadcast_provider_message_number')
    op.execute("drop sequence broadcast_provider_message_number_seq")
    # ### end Alembic commands ###
