|
| 1 | +"""Initial |
| 2 | +
|
| 3 | +Revision ID: f14d9f9ad604 |
| 4 | +Revises: |
| 5 | +Create Date: 2025-07-13 12:04:12.097472 |
| 6 | +
|
| 7 | +""" |
| 8 | +from typing import Sequence, Union |
| 9 | + |
| 10 | +from alembic import op |
| 11 | +import sqlalchemy as sa |
| 12 | +from sqlalchemy.dialects import postgresql |
| 13 | + |
| 14 | +# revision identifiers, used by Alembic. |
| 15 | +revision: str = 'f14d9f9ad604' |
| 16 | +down_revision: Union[str, None] = None |
| 17 | +branch_labels: Union[str, Sequence[str], None] = None |
| 18 | +depends_on: Union[str, Sequence[str], None] = None |
| 19 | + |
| 20 | + |
| 21 | +def upgrade() -> None: |
| 22 | + # ### commands auto generated by Alembic - please adjust! ### |
| 23 | + op.create_table('service_addresses', |
| 24 | + sa.Column('address', sa.String(length=70), nullable=False), |
| 25 | + sa.Column('id', sa.Uuid(), nullable=False), |
| 26 | + sa.PrimaryKeyConstraint('id') |
| 27 | + ) |
| 28 | + op.create_index(op.f('ix_service_addresses_address'), 'service_addresses', ['address'], unique=True) |
| 29 | + op.create_table('service_blocks', |
| 30 | + sa.Column('blockhash', sa.String(length=64), nullable=False), |
| 31 | + sa.Column('transactions', postgresql.ARRAY(sa.String()), nullable=False), |
| 32 | + sa.Column('height', sa.Integer(), nullable=False), |
| 33 | + sa.Column('movements', postgresql.JSONB(astext_type=sa.Text()), nullable=False), |
| 34 | + sa.Column('created', sa.DateTime(), nullable=False), |
| 35 | + sa.Column('timestamp', sa.Integer(), nullable=False), |
| 36 | + sa.Column('prev_blockhash', sa.String(length=64), nullable=True), |
| 37 | + sa.Column('id', sa.Uuid(), nullable=False), |
| 38 | + sa.PrimaryKeyConstraint('id') |
| 39 | + ) |
| 40 | + op.create_index(op.f('ix_service_blocks_blockhash'), 'service_blocks', ['blockhash'], unique=True) |
| 41 | + op.create_index(op.f('ix_service_blocks_height'), 'service_blocks', ['height'], unique=False) |
| 42 | + op.create_index(op.f('ix_service_blocks_prev_blockhash'), 'service_blocks', ['prev_blockhash'], unique=False) |
| 43 | + op.create_table('service_inputs', |
| 44 | + sa.Column('shortcut', sa.String(length=70), nullable=False), |
| 45 | + sa.Column('blockhash', sa.String(length=64), nullable=False), |
| 46 | + sa.Column('txid', sa.String(length=64), nullable=False), |
| 47 | + sa.Column('source_txid', sa.String(length=64), nullable=False), |
| 48 | + sa.Column('index', sa.Integer(), nullable=False), |
| 49 | + sa.Column('id', sa.Uuid(), nullable=False), |
| 50 | + sa.PrimaryKeyConstraint('id') |
| 51 | + ) |
| 52 | + op.create_index(op.f('ix_service_inputs_blockhash'), 'service_inputs', ['blockhash'], unique=False) |
| 53 | + op.create_index(op.f('ix_service_inputs_shortcut'), 'service_inputs', ['shortcut'], unique=True) |
| 54 | + op.create_index(op.f('ix_service_inputs_source_txid'), 'service_inputs', ['source_txid'], unique=False) |
| 55 | + op.create_index(op.f('ix_service_inputs_txid'), 'service_inputs', ['txid'], unique=False) |
| 56 | + op.create_table('service_mempool', |
| 57 | + sa.Column('raw', postgresql.JSONB(astext_type=sa.Text()), nullable=False), |
| 58 | + sa.Column('id', sa.Uuid(), nullable=False), |
| 59 | + sa.PrimaryKeyConstraint('id') |
| 60 | + ) |
| 61 | + op.create_table('service_outputs', |
| 62 | + sa.Column('currency', sa.String(length=64), nullable=False), |
| 63 | + sa.Column('shortcut', sa.String(length=70), nullable=False), |
| 64 | + sa.Column('blockhash', sa.String(length=64), nullable=False), |
| 65 | + sa.Column('address', sa.String(length=70), nullable=False), |
| 66 | + sa.Column('txid', sa.String(length=64), nullable=False), |
| 67 | + sa.Column('amount', sa.Numeric(precision=28, scale=8), nullable=False), |
| 68 | + sa.Column('timelock', sa.Integer(), nullable=False), |
| 69 | + sa.Column('type', sa.String(length=64), nullable=False), |
| 70 | + sa.Column('script', sa.String(), nullable=False), |
| 71 | + sa.Column('asm', sa.String(), nullable=False), |
| 72 | + sa.Column('spent', sa.Boolean(), nullable=False), |
| 73 | + sa.Column('index', sa.Integer(), nullable=False), |
| 74 | + sa.Column('meta', postgresql.JSONB(astext_type=sa.Text()), nullable=False), |
| 75 | + sa.Column('id', sa.Uuid(), nullable=False), |
| 76 | + sa.PrimaryKeyConstraint('id') |
| 77 | + ) |
| 78 | + op.create_index(op.f('ix_service_outputs_address'), 'service_outputs', ['address'], unique=False) |
| 79 | + op.create_index(op.f('ix_service_outputs_blockhash'), 'service_outputs', ['blockhash'], unique=False) |
| 80 | + op.create_index(op.f('ix_service_outputs_currency'), 'service_outputs', ['currency'], unique=False) |
| 81 | + op.create_index(op.f('ix_service_outputs_shortcut'), 'service_outputs', ['shortcut'], unique=True) |
| 82 | + op.create_index(op.f('ix_service_outputs_txid'), 'service_outputs', ['txid'], unique=False) |
| 83 | + op.create_index(op.f('ix_service_outputs_type'), 'service_outputs', ['type'], unique=False) |
| 84 | + op.create_table('service_transactions', |
| 85 | + sa.Column('currencies', postgresql.ARRAY(sa.String(length=64)), nullable=False), |
| 86 | + sa.Column('txid', sa.String(length=64), nullable=False), |
| 87 | + sa.Column('blockhash', sa.String(length=64), nullable=False), |
| 88 | + sa.Column('addresses', postgresql.ARRAY(sa.String()), nullable=False), |
| 89 | + sa.Column('created', sa.DateTime(), nullable=False), |
| 90 | + sa.Column('timestamp', sa.Integer(), nullable=False), |
| 91 | + sa.Column('size', sa.Integer(), nullable=False), |
| 92 | + sa.Column('height', sa.Integer(), nullable=False), |
| 93 | + sa.Column('locktime', sa.Integer(), nullable=False), |
| 94 | + sa.Column('version', sa.Integer(), nullable=False), |
| 95 | + sa.Column('amount', postgresql.JSONB(astext_type=sa.Text()), nullable=False), |
| 96 | + sa.Column('id', sa.Uuid(), nullable=False), |
| 97 | + sa.PrimaryKeyConstraint('id') |
| 98 | + ) |
| 99 | + op.create_index(op.f('ix_service_transactions_addresses'), 'service_transactions', ['addresses'], unique=False) |
| 100 | + op.create_index(op.f('ix_service_transactions_blockhash'), 'service_transactions', ['blockhash'], unique=False) |
| 101 | + op.create_index(op.f('ix_service_transactions_currencies'), 'service_transactions', ['currencies'], unique=False) |
| 102 | + op.create_index(op.f('ix_service_transactions_txid'), 'service_transactions', ['txid'], unique=True) |
| 103 | + op.create_table('service_address_balances', |
| 104 | + sa.Column('balance', sa.Numeric(precision=28, scale=8), nullable=False), |
| 105 | + sa.Column('currency', sa.String(length=64), nullable=False), |
| 106 | + sa.Column('address_id', sa.Uuid(), nullable=False), |
| 107 | + sa.Column('id', sa.Uuid(), nullable=False), |
| 108 | + sa.ForeignKeyConstraint(['address_id'], ['service_addresses.id'], ), |
| 109 | + sa.PrimaryKeyConstraint('address_id', 'id') |
| 110 | + ) |
| 111 | + op.create_index(op.f('ix_service_address_balances_currency'), 'service_address_balances', ['currency'], unique=False) |
| 112 | + # ### end Alembic commands ### |
| 113 | + |
| 114 | + |
| 115 | +def downgrade() -> None: |
| 116 | + # ### commands auto generated by Alembic - please adjust! ### |
| 117 | + op.drop_index(op.f('ix_service_address_balances_currency'), table_name='service_address_balances') |
| 118 | + op.drop_table('service_address_balances') |
| 119 | + op.drop_index(op.f('ix_service_transactions_txid'), table_name='service_transactions') |
| 120 | + op.drop_index(op.f('ix_service_transactions_currencies'), table_name='service_transactions') |
| 121 | + op.drop_index(op.f('ix_service_transactions_blockhash'), table_name='service_transactions') |
| 122 | + op.drop_index(op.f('ix_service_transactions_addresses'), table_name='service_transactions') |
| 123 | + op.drop_table('service_transactions') |
| 124 | + op.drop_index(op.f('ix_service_outputs_type'), table_name='service_outputs') |
| 125 | + op.drop_index(op.f('ix_service_outputs_txid'), table_name='service_outputs') |
| 126 | + op.drop_index(op.f('ix_service_outputs_shortcut'), table_name='service_outputs') |
| 127 | + op.drop_index(op.f('ix_service_outputs_currency'), table_name='service_outputs') |
| 128 | + op.drop_index(op.f('ix_service_outputs_blockhash'), table_name='service_outputs') |
| 129 | + op.drop_index(op.f('ix_service_outputs_address'), table_name='service_outputs') |
| 130 | + op.drop_table('service_outputs') |
| 131 | + op.drop_table('service_mempool') |
| 132 | + op.drop_index(op.f('ix_service_inputs_txid'), table_name='service_inputs') |
| 133 | + op.drop_index(op.f('ix_service_inputs_source_txid'), table_name='service_inputs') |
| 134 | + op.drop_index(op.f('ix_service_inputs_shortcut'), table_name='service_inputs') |
| 135 | + op.drop_index(op.f('ix_service_inputs_blockhash'), table_name='service_inputs') |
| 136 | + op.drop_table('service_inputs') |
| 137 | + op.drop_index(op.f('ix_service_blocks_prev_blockhash'), table_name='service_blocks') |
| 138 | + op.drop_index(op.f('ix_service_blocks_height'), table_name='service_blocks') |
| 139 | + op.drop_index(op.f('ix_service_blocks_blockhash'), table_name='service_blocks') |
| 140 | + op.drop_table('service_blocks') |
| 141 | + op.drop_index(op.f('ix_service_addresses_address'), table_name='service_addresses') |
| 142 | + op.drop_table('service_addresses') |
| 143 | + # ### end Alembic commands ### |
0 commit comments