|
| 1 | +"""Add hotel booking tables and columns |
| 2 | +
|
| 3 | +Revision ID: a1b2c3d4e5f6 |
| 4 | +Revises: 5a0e898174d4 |
| 5 | +Create Date: 2026-04-08 00:00:00.000000 |
| 6 | +
|
| 7 | +""" |
| 8 | + |
| 9 | + |
| 10 | +# revision identifiers, used by Alembic. |
| 11 | +revision = 'a1b2c3d4e5f6' |
| 12 | +down_revision = '4df6bfee2c69' |
| 13 | +branch_labels = None |
| 14 | +depends_on = None |
| 15 | + |
| 16 | +from alembic import op |
| 17 | +import sqlalchemy as sa |
| 18 | +from sqlalchemy.dialects import postgresql |
| 19 | + |
| 20 | + |
| 21 | +try: |
| 22 | + is_sqlite = op.get_context().dialect.name == 'sqlite' |
| 23 | +except Exception: |
| 24 | + is_sqlite = False |
| 25 | + |
| 26 | +if is_sqlite: |
| 27 | + op.get_context().connection.execute('PRAGMA foreign_keys=ON;') |
| 28 | + utcnow_server_default = "(datetime('now', 'utc'))" |
| 29 | +else: |
| 30 | + utcnow_server_default = "timezone('utc', current_timestamp)" |
| 31 | + |
| 32 | +def sqlite_column_reflect_listener(inspector, table, column_info): |
| 33 | + """Adds parenthesis around SQLite datetime defaults for utcnow.""" |
| 34 | + if column_info['default'] == "datetime('now', 'utc')": |
| 35 | + column_info['default'] = utcnow_server_default |
| 36 | + |
| 37 | +sqlite_reflect_kwargs = { |
| 38 | + 'listeners': [('column_reflect', sqlite_column_reflect_listener)] |
| 39 | +} |
| 40 | + |
| 41 | +# =========================================================================== |
| 42 | +# HOWTO: Handle alter statements in SQLite |
| 43 | +# |
| 44 | +# def upgrade(): |
| 45 | +# if is_sqlite: |
| 46 | +# with op.batch_alter_table('table_name', reflect_kwargs=sqlite_reflect_kwargs) as batch_op: |
| 47 | +# batch_op.alter_column('column_name', type_=sa.Unicode(), server_default='', nullable=False) |
| 48 | +# else: |
| 49 | +# op.alter_column('table_name', 'column_name', type_=sa.Unicode(), server_default='', nullable=False) |
| 50 | +# |
| 51 | +# =========================================================================== |
| 52 | + |
| 53 | + |
| 54 | +def upgrade(): |
| 55 | + op.create_table('lottery_run', |
| 56 | + sa.Column('id', sa.Uuid(as_uuid=False), nullable=False), |
| 57 | + sa.Column('created', sa.DateTime(timezone=True), server_default=sa.text(utcnow_server_default), nullable=False), |
| 58 | + sa.Column('last_updated', sa.DateTime(timezone=True), server_default=sa.text(utcnow_server_default), nullable=False), |
| 59 | + sa.Column('external_id', postgresql.JSONB(astext_type=sa.Text()), server_default='{}', nullable=False), |
| 60 | + sa.Column('last_synced', postgresql.JSONB(astext_type=sa.Text()), server_default='{}', nullable=False), |
| 61 | + sa.Column('name', sa.Unicode(), server_default='', nullable=False), |
| 62 | + sa.Column('status', sa.Integer(), server_default='0', nullable=False), |
| 63 | + sa.Column('run_at', sa.DateTime(timezone=True), nullable=True), |
| 64 | + sa.Column('awarded_at', sa.DateTime(timezone=True), nullable=True), |
| 65 | + sa.Column('reverted_at', sa.DateTime(timezone=True), nullable=True), |
| 66 | + sa.Column('lottery_group', sa.Unicode(), server_default='attendee', nullable=False), |
| 67 | + sa.Column('lottery_type', sa.Unicode(), server_default='room', nullable=False), |
| 68 | + sa.Column('cutoff', sa.DateTime(timezone=True), nullable=True), |
| 69 | + sa.Column('hotel_filter', sa.Unicode(), nullable=True), |
| 70 | + sa.Column('room_type_filter', sa.Unicode(), nullable=True), |
| 71 | + sa.Column('entries_considered', sa.Integer(), server_default='0', nullable=False), |
| 72 | + sa.Column('rooms_assigned', sa.Integer(), server_default='0', nullable=False), |
| 73 | + sa.Column('rooms_available_before', sa.Integer(), server_default='0', nullable=False), |
| 74 | + sa.PrimaryKeyConstraint('id', name=op.f('pk_lottery_run')) |
| 75 | + ) |
| 76 | + |
| 77 | + op.create_table('hotel_room_inventory', |
| 78 | + sa.Column('id', sa.Uuid(as_uuid=False), nullable=False), |
| 79 | + sa.Column('created', sa.DateTime(timezone=True), server_default=sa.text(utcnow_server_default), nullable=False), |
| 80 | + sa.Column('last_updated', sa.DateTime(timezone=True), server_default=sa.text(utcnow_server_default), nullable=False), |
| 81 | + sa.Column('external_id', postgresql.JSONB(astext_type=sa.Text()), server_default='{}', nullable=False), |
| 82 | + sa.Column('last_synced', postgresql.JSONB(astext_type=sa.Text()), server_default='{}', nullable=False), |
| 83 | + sa.Column('hotel', sa.Integer(), server_default='0', nullable=False), |
| 84 | + sa.Column('room_type', sa.Integer(), nullable=True), |
| 85 | + sa.Column('suite_type', sa.Integer(), nullable=True), |
| 86 | + sa.Column('quantity', sa.Integer(), server_default='0', nullable=False), |
| 87 | + sa.Column('capacity', sa.Integer(), server_default='2', nullable=False), |
| 88 | + sa.Column('min_capacity', sa.Integer(), server_default='1', nullable=False), |
| 89 | + sa.Column('name', sa.Unicode(), server_default='', nullable=False), |
| 90 | + sa.Column('is_suite', sa.Boolean(), server_default='False', nullable=False), |
| 91 | + sa.Column('active', sa.Boolean(), server_default='True', nullable=False), |
| 92 | + sa.Column('vault_reference', sa.Unicode(), nullable=True), |
| 93 | + sa.PrimaryKeyConstraint('id', name=op.f('pk_hotel_room_inventory')) |
| 94 | + ) |
| 95 | + |
| 96 | + op.create_table('hotel_export_log', |
| 97 | + sa.Column('id', sa.Uuid(as_uuid=False), nullable=False), |
| 98 | + sa.Column('created', sa.DateTime(timezone=True), server_default=sa.text(utcnow_server_default), nullable=False), |
| 99 | + sa.Column('last_updated', sa.DateTime(timezone=True), server_default=sa.text(utcnow_server_default), nullable=False), |
| 100 | + sa.Column('external_id', postgresql.JSONB(astext_type=sa.Text()), server_default='{}', nullable=False), |
| 101 | + sa.Column('last_synced', postgresql.JSONB(astext_type=sa.Text()), server_default='{}', nullable=False), |
| 102 | + sa.Column('hotel', sa.Integer(), server_default='0', nullable=False), |
| 103 | + sa.Column('export_type', sa.Unicode(), server_default='', nullable=False), |
| 104 | + sa.Column('exported_at', sa.DateTime(timezone=True), nullable=True), |
| 105 | + sa.Column('exported_by', sa.Unicode(), server_default='', nullable=False), |
| 106 | + sa.Column('record_count', sa.Integer(), server_default='0', nullable=False), |
| 107 | + sa.Column('notes', sa.Unicode(), server_default='', nullable=False), |
| 108 | + sa.PrimaryKeyConstraint('id', name=op.f('pk_hotel_export_log')) |
| 109 | + ) |
| 110 | + |
| 111 | + op.add_column('lottery_application', sa.Column('cc_token', sa.Unicode(), nullable=True)) |
| 112 | + op.add_column('lottery_application', sa.Column('cc_last_four', sa.Unicode(), nullable=True)) |
| 113 | + op.add_column('lottery_application', sa.Column('cc_card_type', sa.Unicode(), nullable=True)) |
| 114 | + op.add_column('lottery_application', sa.Column('cc_captured_at', sa.DateTime(timezone=True), nullable=True)) |
| 115 | + op.add_column('lottery_application', sa.Column('hotel_confirmation_number', sa.Unicode(), nullable=True)) |
| 116 | + op.add_column('lottery_application', sa.Column('special_requests', sa.Unicode(), server_default='', nullable=False)) |
| 117 | + op.add_column('lottery_application', sa.Column('last_modified_at', sa.DateTime(timezone=True), nullable=True)) |
| 118 | + op.add_column('lottery_application', sa.Column('lottery_run_id', sa.Uuid(as_uuid=False), nullable=True)) |
| 119 | + op.create_foreign_key( |
| 120 | + op.f('fk_lottery_application_lottery_run_id_lottery_run'), |
| 121 | + 'lottery_application', 'lottery_run', |
| 122 | + ['lottery_run_id'], ['id'] |
| 123 | + ) |
| 124 | + |
| 125 | + |
| 126 | +def downgrade(): |
| 127 | + op.drop_constraint(op.f('fk_lottery_application_lottery_run_id_lottery_run'), 'lottery_application', type_='foreignkey') |
| 128 | + op.drop_column('lottery_application', 'lottery_run_id') |
| 129 | + op.drop_column('lottery_application', 'last_modified_at') |
| 130 | + op.drop_column('lottery_application', 'special_requests') |
| 131 | + op.drop_column('lottery_application', 'hotel_confirmation_number') |
| 132 | + op.drop_column('lottery_application', 'cc_captured_at') |
| 133 | + op.drop_column('lottery_application', 'cc_card_type') |
| 134 | + op.drop_column('lottery_application', 'cc_last_four') |
| 135 | + op.drop_column('lottery_application', 'cc_token') |
| 136 | + op.drop_table('hotel_export_log') |
| 137 | + op.drop_table('hotel_room_inventory') |
| 138 | + op.drop_table('lottery_run') |
0 commit comments