|
| 1 | +"""add Match, MatchStatus, SuggestedTime, AvailableTime. delete Schedule, ScheduleStatus |
| 2 | +
|
| 3 | +Revision ID: d6ee93e07a70 |
| 4 | +Revises: df571b763807 |
| 5 | +Create Date: 2025-03-11 21:11:38.464490 |
| 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 = 'd6ee93e07a70' |
| 16 | +down_revision: Union[str, None] = 'df571b763807' |
| 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('match_status', |
| 24 | + sa.Column('id', sa.Integer(), nullable=False), |
| 25 | + sa.Column('name', sa.String(length=80), nullable=False), |
| 26 | + sa.PrimaryKeyConstraint('id') |
| 27 | + ) |
| 28 | + op.bulk_insert( |
| 29 | + sa.table( |
| 30 | + "match_status", |
| 31 | + sa.Column("id", sa.Integer(), nullable=False), |
| 32 | + sa.Column("name", sa.String(length=80), nullable=False), |
| 33 | + ), |
| 34 | + [ |
| 35 | + {"id": 1, "name": "PENDING_ADMIN_APPROVAL"}, |
| 36 | + {"id": 2, "name": "APPROVED"}, |
| 37 | + {"id": 3, "name": "REJECTED"}, |
| 38 | + {"id": 4, "name": "PENDING_PARTICIPANT_RESPONSE"}, |
| 39 | + {"id": 5, "name": "PENDING_VOLUNTEER_RESPONSE"}, |
| 40 | + {"id": 6, "name": "SCHEDULED"}, |
| 41 | + {"id": 7, "name": "DECLINED"}, |
| 42 | + {"id": 8, "name": "CANCELLED"}, |
| 43 | + {"id": 9, "name": "COMPLETED"}, |
| 44 | + ], |
| 45 | + ) |
| 46 | + op.create_table('available_times', |
| 47 | + sa.Column('time_block_id', sa.Integer(), nullable=False), |
| 48 | + sa.Column('user_id', sa.UUID(), nullable=False), |
| 49 | + sa.ForeignKeyConstraint(['time_block_id'], ['time_blocks.id'], ), |
| 50 | + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), |
| 51 | + sa.PrimaryKeyConstraint('time_block_id', 'user_id') |
| 52 | + ) |
| 53 | + op.create_table('matches', |
| 54 | + sa.Column('id', sa.Integer(), nullable=False), |
| 55 | + sa.Column('participant_id', sa.UUID(), nullable=False), |
| 56 | + sa.Column('volunteer_id', sa.UUID(), nullable=False), |
| 57 | + sa.Column('chosen_time_block_id', sa.Integer(), nullable=True), |
| 58 | + sa.Column('match_status_id', sa.Integer(), nullable=False), |
| 59 | + sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True), |
| 60 | + sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True), |
| 61 | + sa.ForeignKeyConstraint(['chosen_time_block_id'], ['time_blocks.id'], ), |
| 62 | + sa.ForeignKeyConstraint(['match_status_id'], ['match_status.id'], ), |
| 63 | + sa.ForeignKeyConstraint(['participant_id'], ['users.id'], ), |
| 64 | + sa.ForeignKeyConstraint(['volunteer_id'], ['users.id'], ), |
| 65 | + sa.PrimaryKeyConstraint('id') |
| 66 | + ) |
| 67 | + op.create_table('suggested_times', |
| 68 | + sa.Column('match_id', sa.Integer(), nullable=False), |
| 69 | + sa.Column('time_block_id', sa.Integer(), nullable=False), |
| 70 | + sa.ForeignKeyConstraint(['match_id'], ['matches.id'], ), |
| 71 | + sa.ForeignKeyConstraint(['time_block_id'], ['time_blocks.id'], ), |
| 72 | + sa.PrimaryKeyConstraint('match_id', 'time_block_id') |
| 73 | + ) |
| 74 | + op.drop_table('schedules') |
| 75 | + op.drop_table('schedule_status') |
| 76 | + op.drop_constraint('time_blocks_schedule_id_fkey', 'time_blocks', type_='foreignkey') |
| 77 | + op.drop_column('time_blocks', 'schedule_id') |
| 78 | + op.drop_column('time_blocks', 'end_time') |
| 79 | + # ### end Alembic commands ### |
| 80 | + |
| 81 | + |
| 82 | +def downgrade() -> None: |
| 83 | + # ### commands auto generated by Alembic - please adjust! ### |
| 84 | + op.add_column('time_blocks', sa.Column('end_time', postgresql.TIMESTAMP(), autoincrement=False, nullable=True)) |
| 85 | + op.add_column('time_blocks', sa.Column('schedule_id', sa.INTEGER(), autoincrement=False, nullable=False)) |
| 86 | + op.create_foreign_key('time_blocks_schedule_id_fkey', 'time_blocks', 'schedules', ['schedule_id'], ['id']) |
| 87 | + op.create_table('schedule_status', |
| 88 | + sa.Column('id', sa.INTEGER(), server_default=sa.text("nextval('schedule_status_id_seq'::regclass)"), autoincrement=True, nullable=False), |
| 89 | + sa.Column('name', sa.VARCHAR(length=80), autoincrement=False, nullable=False), |
| 90 | + sa.PrimaryKeyConstraint('id', name='schedule_status_pkey'), |
| 91 | + postgresql_ignore_search_path=False |
| 92 | + ) |
| 93 | + op.create_table('schedules', |
| 94 | + sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), |
| 95 | + sa.Column('scheduled_time', postgresql.TIMESTAMP(), autoincrement=False, nullable=True), |
| 96 | + sa.Column('duration', postgresql.INTERVAL(), autoincrement=False, nullable=True), |
| 97 | + sa.Column('status_id', sa.INTEGER(), autoincrement=False, nullable=False), |
| 98 | + sa.ForeignKeyConstraint(['status_id'], ['schedule_status.id'], name='schedules_status_id_fkey'), |
| 99 | + sa.PrimaryKeyConstraint('id', name='schedules_pkey') |
| 100 | + ) |
| 101 | + op.drop_table('suggested_times') |
| 102 | + op.drop_table('matches') |
| 103 | + op.drop_table('available_times') |
| 104 | + op.drop_table('match_status') |
| 105 | + # ### end Alembic commands ### |
0 commit comments