|
| 1 | +"""rename paging_token columns to TOID |
| 2 | +
|
| 3 | +Revision ID: 371cdad348d3 |
| 4 | +Revises: 52e5e68af772 |
| 5 | +Create Date: 2025-11-11 12:18:35.680184 |
| 6 | +
|
| 7 | +""" |
| 8 | +from typing import Sequence |
| 9 | + |
| 10 | +from alembic import context, op |
| 11 | +import sqlalchemy as sa |
| 12 | + |
| 13 | + |
| 14 | +# revision identifiers, used by Alembic. |
| 15 | +revision: str = '371cdad348d3' |
| 16 | +down_revision: str | None = '52e5e68af772' |
| 17 | +branch_labels: str | Sequence[str] | None = None |
| 18 | +depends_on: str | Sequence[str] | None = None |
| 19 | + |
| 20 | + |
| 21 | +def upgrade() -> None: |
| 22 | + # turn off FK constraints for SQLite to allow table recreation |
| 23 | + dialect_name = context.get_context().dialect.name |
| 24 | + if dialect_name == 'sqlite': |
| 25 | + op.execute("PRAGMA foreign_keys=OFF") |
| 26 | + |
| 27 | + with op.batch_alter_table('distribution_txs', schema=None) as batch_op: |
| 28 | + batch_op.alter_column('paging_token', new_column_name='toid') |
| 29 | + |
| 30 | + with op.batch_alter_table('minted_blocks', schema=None) as batch_op: |
| 31 | + batch_op.alter_column('paging_token', new_column_name='toid') |
| 32 | + batch_op.drop_index(batch_op.f('idx_block_toid')) |
| 33 | + |
| 34 | + op.create_index('idx_block_toid', 'minted_blocks', [sa.literal_column('toid DESC')], unique=True) |
| 35 | + |
| 36 | + with op.batch_alter_table('sinking_txs', schema=None) as batch_op: |
| 37 | + batch_op.alter_column('paging_token', new_column_name='toid') |
| 38 | + batch_op.drop_index(batch_op.f('idx_stx_toid')) |
| 39 | + |
| 40 | + op.create_index('idx_stx_toid', 'sinking_txs', [sa.literal_column('toid DESC')], unique=True) |
| 41 | + |
| 42 | + with op.batch_alter_table('test_distribution_txs', schema=None) as batch_op: |
| 43 | + batch_op.alter_column('paging_token', new_column_name='toid') |
| 44 | + |
| 45 | + with op.batch_alter_table('test_minted_blocks', schema=None) as batch_op: |
| 46 | + batch_op.alter_column('paging_token', new_column_name='toid') |
| 47 | + |
| 48 | + with op.batch_alter_table('test_sinking_txs', schema=None) as batch_op: |
| 49 | + batch_op.alter_column('paging_token', new_column_name='toid') |
| 50 | + |
| 51 | + if dialect_name == 'sqlite': |
| 52 | + op.execute("PRAGMA foreign_keys=ON") |
| 53 | + |
| 54 | + |
| 55 | +def downgrade() -> None: |
| 56 | + dialect_name = context.get_context().dialect.name |
| 57 | + if dialect_name == 'sqlite': |
| 58 | + op.execute("PRAGMA foreign_keys=OFF") |
| 59 | + |
| 60 | + with op.batch_alter_table('test_sinking_txs', schema=None) as batch_op: |
| 61 | + batch_op.alter_column('toid', new_column_name='paging_token') |
| 62 | + |
| 63 | + with op.batch_alter_table('test_minted_blocks', schema=None) as batch_op: |
| 64 | + batch_op.alter_column('toid', new_column_name='paging_token') |
| 65 | + |
| 66 | + with op.batch_alter_table('test_distribution_txs', schema=None) as batch_op: |
| 67 | + batch_op.alter_column('toid', new_column_name='paging_token') |
| 68 | + |
| 69 | + with op.batch_alter_table('sinking_txs', schema=None) as batch_op: |
| 70 | + batch_op.alter_column('toid', new_column_name='paging_token') |
| 71 | + batch_op.drop_index('idx_stx_toid') |
| 72 | + |
| 73 | + op.create_index(op.f('idx_stx_toid'), 'sinking_txs', [sa.literal_column('paging_token DESC')], unique=True) |
| 74 | + |
| 75 | + with op.batch_alter_table('minted_blocks', schema=None) as batch_op: |
| 76 | + batch_op.alter_column('toid', new_column_name='paging_token') |
| 77 | + batch_op.drop_index('idx_block_toid') |
| 78 | + |
| 79 | + op.create_index(op.f('idx_block_toid'), 'minted_blocks', [sa.literal_column('paging_token DESC')], unique=True) |
| 80 | + |
| 81 | + with op.batch_alter_table('distribution_txs', schema=None) as batch_op: |
| 82 | + batch_op.alter_column('toid', new_column_name='paging_token') |
| 83 | + |
| 84 | + if dialect_name == 'sqlite': |
| 85 | + op.execute("PRAGMA foreign_keys=ON") |
0 commit comments