Working migration

pull/882/head
kompotkot 2023-08-03 09:52:50 +00:00
rodzic 3b265ad15d
commit 39a64cf454
1 zmienionych plików z 10 dodań i 8 usunięć

Wyświetl plik

@ -5,6 +5,8 @@ Revises: dedd8a7d0624
Create Date: 2023-08-02 18:28:14.724453
"""
import uuid
from alembic import op
import sqlalchemy as sa
@ -36,9 +38,9 @@ def upgrade():
op.create_foreign_key(op.f('fk_registered_contracts_blockchain_id_blockchains'), 'registered_contracts', 'blockchains', ['blockchain_id'], ['id'], ondelete='CASCADE')
# Manual - Start
op.execute("INSERT INTO blockchains (name, chain_id, testnet) VALUES ('polygon', 137, FALSE);")
op.execute("INSERT INTO blockchains (name, chain_id, testnet) VALUES ('mumbai', 80001, TRUE);")
op.execute("UPDATE registered_contracts SET blockchain_id = (SELECT id FROM blockchains WHERE blockchains.name = contracts.blockchain);")
op.execute(f"INSERT INTO blockchains (id, name, chain_id, testnet) VALUES ('{str(uuid.uuid4())}', 'polygon', 137, FALSE);")
op.execute(f"INSERT INTO blockchains (id, name, chain_id, testnet) VALUES ('{str(uuid.uuid4())}', 'mumbai', 80001, TRUE);")
op.execute("UPDATE registered_contracts SET blockchain_id = (SELECT id FROM blockchains WHERE blockchains.name = registered_contracts.blockchain);")
op.alter_column("registered_contracts", "blockchain_id", nullable=False)
# Manual - End
@ -57,12 +59,12 @@ def upgrade():
op.create_index(op.f('ix_call_request_types_request_type'), 'call_request_types', ['request_type'], unique=True)
op.add_column('call_requests', sa.Column('call_request_type_id', sa.UUID(), nullable=True))
op.create_foreign_key(op.f('fk_call_requests_call_request_id_call_request_types'), 'call_requests', 'call_request_types', ['call_request_id'], ['id'], ondelete='CASCADE')
op.create_foreign_key(op.f('fk_call_requests_call_request_type_id_call_request_types'), 'call_requests', 'call_request_types', ['call_request_type_id'], ['id'], ondelete='CASCADE')
# Manual - Start
op.execute("INSERT INTO call_request_types (request_type) VALUES ('raw');")
op.execute("INSERT INTO call_request_types (request_type) VALUES ('dropper-v0.2.0');")
op.execute("UPDATE call_requests SET request_type = (SELECT id FROM call_request_types INNER JOIN registered_contracts ON call_requests.registered_contract_id = registered_contracts.id WHERE call_request_types.request_type = registered_contracts.contract_type);")
op.execute(f"INSERT INTO call_request_types (id, request_type) VALUES ('{str(uuid.uuid4())}', 'raw');")
op.execute(f"INSERT INTO call_request_types (id, request_type) VALUES ('{str(uuid.uuid4())}', 'dropper-v0.2.0');")
op.execute("UPDATE call_requests SET call_request_type_id = (SELECT call_request_types.id FROM call_request_types INNER JOIN registered_contracts ON call_requests.registered_contract_id = registered_contracts.id WHERE call_request_types.request_type = registered_contracts.contract_type);")
op.alter_column("call_requests", "call_request_type_id", nullable=False)
# Manual - End
@ -133,7 +135,7 @@ def downgrade():
# Copy type values
# ...
op.drop_constraint(op.f('fk_call_requests_call_request_id_call_request_types'), 'call_requests', type_='foreignkey')
op.drop_constraint(op.f('fk_call_requests_call_request_type_id_call_request_types'), 'call_requests', type_='foreignkey')
op.drop_column('call_requests', 'call_request_type_id')
op.drop_index(op.f('ix_call_request_types_request_type'), table_name='call_request_types')