|
| 1 | +"""create courts table |
| 2 | +
|
| 3 | +Revision ID: 3469289a7e06 |
| 4 | +Revises: 6458e0bc3e9d |
| 5 | +Create Date: 2023-09-11 13:36:28.464161 |
| 6 | +
|
| 7 | +""" |
| 8 | + |
| 9 | +import sqlalchemy as sa |
| 10 | + |
| 11 | +from alembic import op |
| 12 | + |
| 13 | +# revision identifiers, used by Alembic. |
| 14 | +revision: str | None = '3469289a7e06' |
| 15 | +down_revision: str | None = '6458e0bc3e9d' |
| 16 | +branch_labels: str | None = None |
| 17 | +depends_on: str | None = None |
| 18 | + |
| 19 | + |
| 20 | +def upgrade() -> None: |
| 21 | + op.create_table( |
| 22 | + 'courts', |
| 23 | + sa.Column('id', sa.BigInteger(), nullable=False), |
| 24 | + sa.Column('name', sa.Text(), nullable=False), |
| 25 | + sa.Column('created', sa.DateTime(timezone=True), nullable=False), |
| 26 | + sa.Column('tournament_id', sa.BigInteger(), nullable=False), |
| 27 | + sa.ForeignKeyConstraint( |
| 28 | + ['tournament_id'], |
| 29 | + ['tournaments.id'], |
| 30 | + ), |
| 31 | + sa.PrimaryKeyConstraint('id'), |
| 32 | + ) |
| 33 | + op.create_index(op.f('ix_courts_id'), 'courts', ['id'], unique=False) |
| 34 | + op.add_column('matches', sa.Column('court_id', sa.BigInteger(), nullable=True)) |
| 35 | + op.create_foreign_key('matches_courts_fkey', 'matches', 'courts', ['court_id'], ['id']) |
| 36 | + op.create_index(op.f('ix_courts_tournament_id'), 'courts', ['tournament_id'], unique=False) |
| 37 | + op.add_column( |
| 38 | + 'tournaments', |
| 39 | + sa.Column('auto_assign_courts', sa.Boolean(), server_default='f', nullable=False), |
| 40 | + ) |
| 41 | + op.drop_column('matches', 'label') |
| 42 | + |
| 43 | + |
| 44 | +def downgrade() -> None: |
| 45 | + op.add_column('matches', sa.Column('label', sa.Text(), nullable=True, server_default='')) |
| 46 | + op.alter_column('matches', 'label', server_default=None) |
| 47 | + op.drop_column('tournaments', 'auto_assign_courts') |
| 48 | + op.drop_index(op.f('ix_courts_tournament_id'), table_name='courts') |
| 49 | + op.drop_constraint('matches_courts_fkey', 'matches', type_='foreignkey') |
| 50 | + op.drop_column('matches', 'court_id') |
| 51 | + op.drop_index(op.f('ix_courts_id'), table_name='courts') |
| 52 | + op.drop_table('courts') |
0 commit comments