<reponame>danielsemkowicz/chia-monitor
"""Remove unique constraint on ts for all tables

Revision ID: 664882eb4c78
Revises: <KEY>
Create Date: 2021-07-29 23:28:39.161379

"""
import sqlalchemy as sa
from alembic import op


# revision identifiers, used by Alembic.
revision = '<KEY>'
down_revision = '<KEY>'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('blockchain_state_events', schema=None) as batch_op:
        batch_op.drop_constraint('pk_blockchain_state_events')
        batch_op.add_column(sa.Column('id', sa.Integer(), autoincrement=True, nullable=False))
        batch_op.create_index(batch_op.f('ix_blockchain_state_events_ts'), ['ts'], unique=False)
        batch_op.create_primary_key('pk_blockchain_state_events', ['id'])

    with op.batch_alter_table('connection_events', schema=None) as batch_op:
        batch_op.drop_constraint('pk_connection_events')
        batch_op.add_column(sa.Column('id', sa.Integer(), autoincrement=True, nullable=False))
        batch_op.create_index(batch_op.f('ix_connection_events_ts'), ['ts'], unique=False)
        batch_op.create_primary_key('pk_connection_events', ['id'])

    with op.batch_alter_table('harvester_events', schema=None) as batch_op:
        batch_op.drop_constraint('pk_harvester_events')
        batch_op.add_column(sa.Column('id', sa.Integer(), autoincrement=True, nullable=False))
        batch_op.create_index(batch_op.f('ix_harvester_events_ts'), ['ts'], unique=False)
        batch_op.create_primary_key('pk_harvester_events', ['id'])

    with op.batch_alter_table('pool_state_events', schema=None) as batch_op:
        batch_op.drop_constraint('pk_pool_state_events')
        batch_op.add_column(sa.Column('id', sa.Integer(), autoincrement=True, nullable=False))
        batch_op.create_index(batch_op.f('ix_pool_state_events_ts'), ['ts'], unique=False)
        batch_op.create_primary_key('pk_pool_state_events', ['id'])

    with op.batch_alter_table('price_events', schema=None) as batch_op:
        batch_op.drop_constraint('pk_price_events')
        batch_op.add_column(sa.Column('id', sa.Integer(), autoincrement=True, nullable=False))
        batch_op.create_index(batch_op.f('ix_price_events_ts'), ['ts'], unique=False)
        batch_op.create_primary_key('pk_price_events', ['id'])

    with op.batch_alter_table('wallet_balance_events', schema=None) as batch_op:
        batch_op.drop_constraint('pk_wallet_balance_events')
        batch_op.add_column(sa.Column('id', sa.Integer(), autoincrement=True, nullable=False))
        batch_op.create_index(batch_op.f('ix_wallet_balance_events_ts'), ['ts'], unique=False)
        batch_op.create_primary_key('pk_wallet_balance_events', ['id'])

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('wallet_balance_events', schema=None) as batch_op:
        batch_op.drop_constraint('pk_wallet_balance_events')
        batch_op.drop_index(batch_op.f('ix_wallet_balance_events_ts'))
        batch_op.drop_column('id')
        batch_op.create_primary_key('pk_wallet_balance_events', ['ts'])

    with op.batch_alter_table('price_events', schema=None) as batch_op:
        batch_op.drop_constraint('pk_price_events')
        batch_op.drop_index(batch_op.f('ix_price_events_ts'))
        batch_op.drop_column('id')
        batch_op.create_primary_key('pk_price_events', ['ts'])

    with op.batch_alter_table('pool_state_events', schema=None) as batch_op:
        batch_op.drop_constraint('pk_pool_state_events')
        batch_op.drop_index(batch_op.f('ix_pool_state_events_ts'))
        batch_op.drop_column('id')
        batch_op.create_primary_key('pk_pool_state_events', ['ts', 'p2_singleton_puzzle_hash'])

    with op.batch_alter_table('harvester_events', schema=None) as batch_op:
        batch_op.drop_constraint('pk_harvester_events')
        batch_op.drop_index(batch_op.f('ix_harvester_events_ts'))
        batch_op.drop_column('id')
        batch_op.create_primary_key('pk_harvester_events', ['ts', 'host'])

    with op.batch_alter_table('connection_events', schema=None) as batch_op:
        batch_op.drop_constraint('pk_connection_events')
        batch_op.drop_index(batch_op.f('ix_connection_events_ts'))
        batch_op.drop_column('id')
        batch_op.create_primary_key('pk_connection_events', ['ts'])

    with op.batch_alter_table('blockchain_state_events', schema=None) as batch_op:
        batch_op.drop_constraint('pk_blockchain_state_events')
        batch_op.drop_index(batch_op.f('ix_blockchain_state_events_ts'))
        batch_op.drop_column('id')
        batch_op.create_primary_key('pk_blockchain_state_events', ['ts'])

    # ### end Alembic commands ###

"""Remove unique constraint on ts for all tables

Revision ID: 664882eb4c78
Revises: <KEY>
Create Date: 2021-07-29 23:28:39.161379

"""
import sqlalchemy as sa
from alembic import op


# revision identifiers, used by Alembic.
revision = '<KEY>'
down_revision = '<KEY>'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('blockchain_state_events', schema=None) as batch_op:
        batch_op.drop_constraint('pk_blockchain_state_events')
        batch_op.add_column(sa.Column('id', sa.Integer(), autoincrement=True, nullable=False))
        batch_op.create_index(batch_op.f('ix_blockchain_state_events_ts'), ['ts'], unique=False)
        batch_op.create_primary_key('pk_blockchain_state_events', ['id'])

    with op.batch_alter_table('connection_events', schema=None) as batch_op:
        batch_op.drop_constraint('pk_connection_events')
        batch_op.add_column(sa.Column('id', sa.Integer(), autoincrement=True, nullable=False))
        batch_op.create_index(batch_op.f('ix_connection_events_ts'), ['ts'], unique=False)
        batch_op.create_primary_key('pk_connection_events', ['id'])

    with op.batch_alter_table('harvester_events', schema=None) as batch_op:
        batch_op.drop_constraint('pk_harvester_events')
        batch_op.add_column(sa.Column('id', sa.Integer(), autoincrement=True, nullable=False))
        batch_op.create_index(batch_op.f('ix_harvester_events_ts'), ['ts'], unique=False)
        batch_op.create_primary_key('pk_harvester_events', ['id'])

    with op.batch_alter_table('pool_state_events', schema=None) as batch_op:
        batch_op.drop_constraint('pk_pool_state_events')
        batch_op.add_column(sa.Column('id', sa.Integer(), autoincrement=True, nullable=False))
        batch_op.create_index(batch_op.f('ix_pool_state_events_ts'), ['ts'], unique=False)
        batch_op.create_primary_key('pk_pool_state_events', ['id'])

    with op.batch_alter_table('price_events', schema=None) as batch_op:
        batch_op.drop_constraint('pk_price_events')
        batch_op.add_column(sa.Column('id', sa.Integer(), autoincrement=True, nullable=False))
        batch_op.create_index(batch_op.f('ix_price_events_ts'), ['ts'], unique=False)
        batch_op.create_primary_key('pk_price_events', ['id'])

    with op.batch_alter_table('wallet_balance_events', schema=None) as batch_op:
        batch_op.drop_constraint('pk_wallet_balance_events')
        batch_op.add_column(sa.Column('id', sa.Integer(), autoincrement=True, nullable=False))
        batch_op.create_index(batch_op.f('ix_wallet_balance_events_ts'), ['ts'], unique=False)
        batch_op.create_primary_key('pk_wallet_balance_events', ['id'])

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('wallet_balance_events', schema=None) as batch_op:
        batch_op.drop_constraint('pk_wallet_balance_events')
        batch_op.drop_index(batch_op.f('ix_wallet_balance_events_ts'))
        batch_op.drop_column('id')
        batch_op.create_primary_key('pk_wallet_balance_events', ['ts'])

    with op.batch_alter_table('price_events', schema=None) as batch_op:
        batch_op.drop_constraint('pk_price_events')
        batch_op.drop_index(batch_op.f('ix_price_events_ts'))
        batch_op.drop_column('id')
        batch_op.create_primary_key('pk_price_events', ['ts'])

    with op.batch_alter_table('pool_state_events', schema=None) as batch_op:
        batch_op.drop_constraint('pk_pool_state_events')
        batch_op.drop_index(batch_op.f('ix_pool_state_events_ts'))
        batch_op.drop_column('id')
        batch_op.create_primary_key('pk_pool_state_events', ['ts', 'p2_singleton_puzzle_hash'])

    with op.batch_alter_table('harvester_events', schema=None) as batch_op:
        batch_op.drop_constraint('pk_harvester_events')
        batch_op.drop_index(batch_op.f('ix_harvester_events_ts'))
        batch_op.drop_column('id')
        batch_op.create_primary_key('pk_harvester_events', ['ts', 'host'])

    with op.batch_alter_table('connection_events', schema=None) as batch_op:
        batch_op.drop_constraint('pk_connection_events')
        batch_op.drop_index(batch_op.f('ix_connection_events_ts'))
        batch_op.drop_column('id')
        batch_op.create_primary_key('pk_connection_events', ['ts'])

    with op.batch_alter_table('blockchain_state_events', schema=None) as batch_op:
        batch_op.drop_constraint('pk_blockchain_state_events')
        batch_op.drop_index(batch_op.f('ix_blockchain_state_events_ts'))
        batch_op.drop_column('id')
        batch_op.create_primary_key('pk_blockchain_state_events', ['ts'])

    # ### end Alembic commands ###
Remove unique constraint on ts for all tables  Revision ID: 664882eb4c78 Revises: <KEY> Create Date: 2021-07-29 23:28:39.161379 # revision identifiers, used by Alembic. # ### commands auto generated by Alembic - please adjust! ### # ### end Alembic commands ### # ### commands auto generated by Alembic - please adjust! ### # ### end Alembic commands ###