Skip to content

Commit 551d6bd

Browse files
committed
update match schema
- comment out ensure_ses_templates - create migration file
1 parent 9423e3a commit 551d6bd

File tree

9 files changed

+181
-76
lines changed

9 files changed

+181
-76
lines changed

backend/alembic.ini

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ version_path_separator = os # Use os.pathsep. Default configuration used for ne
7777
# black.options = -l 79 REVISION_SCRIPT_FILENAME
7878

7979
# lint with attempts to fix using "ruff" - use the exec runner, execute a binary
80-
hooks = ruff
81-
ruff.type = exec
82-
ruff.executable = %(here)s/.venv/bin/ruff
83-
ruff.options = check --fix REVISION_SCRIPT_FILENAME
80+
; hooks = ruff
81+
; ruff.type = exec
82+
; ruff.executable = %(here)s/.venv/bin/ruff
83+
; ruff.options = check --fix REVISION_SCRIPT_FILENAME
8484

8585
# Logging configuration
8686
# Every time you want to define a new sub-logger, you need to add it to loggers or it won't show up.

backend/app/models/Match.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import enum
2+
3+
from sqlalchemy import Column, DateTime, ForeignKey, Integer
4+
from sqlalchemy.dialects.postgresql import UUID
5+
from sqlalchemy.orm import relationship
6+
from sqlalchemy.sql import func
7+
8+
from .Base import Base
9+
10+
11+
class Match(Base):
12+
__tablename__ = "matches"
13+
14+
id = Column(Integer, primary_key=True)
15+
16+
participant_id = Column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=False)
17+
volunteer_id = Column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=False)
18+
19+
# the chosen time block
20+
chosen_time_block_id = Column(Integer, ForeignKey("time_blocks.id"), nullable=True)
21+
22+
match_status_id = Column(
23+
Integer, ForeignKey("match_status.id"), nullable=False, default=1
24+
)
25+
26+
created_at = Column(DateTime(timezone=True), server_default=func.now())
27+
updated_at = Column(
28+
DateTime(timezone=True), server_default=func.now(), onupdate=func.now()
29+
)
30+
31+
match_status = relationship("MatchStatus")
32+
33+
participant = relationship(
34+
"User", foreign_keys=[participant_id], back_populates="matches"
35+
)
36+
volunteer = relationship(
37+
"User", foreign_keys=[volunteer_id], back_populates="matches"
38+
)
39+
40+
confirmed_time = relationship(
41+
"TimeBlock", back_populates="confirmed_match", uselist=False
42+
)
43+
suggested_time_blocks = relationship(
44+
"TimeBlock", back_populates="suggested_matches"
45+
)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from .Base import Base
44

55

6-
class ScheduleStatus(Base):
7-
__tablename__ = "schedule_status"
6+
class MatchStatus(Base):
7+
__tablename__ = "match_status"
88
id = Column(Integer, primary_key=True)
99
name = Column(String(80), nullable=False)

backend/app/models/Matches.py

Lines changed: 0 additions & 46 deletions
This file was deleted.

backend/app/models/Schedule.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

backend/app/models/User.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ class User(Base):
2222
availability = relationship(
2323
"TimeBlock", secondary="available_times", back_populates="users"
2424
)
25+
26+
participant_matches = relationship("Match", back_populates="participant")
27+
28+
volunteer_matches = relationship("Match", back_populates="volunteer")

backend/app/models/__init__.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,30 @@
55

66
from app.utilities.constants import LOGGER_NAME
77

8+
from .AvailableTime import available_times
9+
810
# Make sure all models are here to reflect all current models
911
# when autogenerating new migration
1012
from .Base import Base
13+
from .Match import Match
14+
from .MatchStatus import MatchStatus
1115
from .Role import Role
12-
from .Schedule import Schedule
13-
from .ScheduleStatus import ScheduleStatus
16+
from .SuggestedTime import suggested_times
1417
from .TimeBlock import TimeBlock
1518
from .User import User
1619

1720
# Used to avoid import errors for the models
18-
__all__ = ["Base", "User", "Role", "Schedule", "ScheduleStatus", "TimeBlock"]
21+
__all__ = [
22+
"Base",
23+
"User",
24+
"Role",
25+
"TimeBlock",
26+
"Match",
27+
"MatchStatus",
28+
"User",
29+
"available_times",
30+
"suggested_times",
31+
]
1932

2033
log = logging.getLogger(LOGGER_NAME("models"))
2134

backend/app/server.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
from fastapi import FastAPI
77

88
from . import models
9-
from .routes import schedule, send_email, user
9+
from .routes import send_email, user
1010
from .utilities.constants import LOGGER_NAME
1111
from .utilities.firebase_init import initialize_firebase
12-
from .utilities.ses.ses_init import ensure_ses_templates
12+
# from .utilities.ses.ses_init import ensure_ses_templates
1313

1414
load_dotenv()
1515

@@ -19,7 +19,7 @@
1919
@asynccontextmanager
2020
async def lifespan(_: FastAPI):
2121
log.info("Starting up...")
22-
ensure_ses_templates()
22+
# ensure_ses_templates()
2323
models.run_migrations()
2424
initialize_firebase()
2525
yield
@@ -30,8 +30,8 @@ async def lifespan(_: FastAPI):
3030
# running-alembic-migrations-on-fastapi-startup
3131
app = FastAPI(lifespan=lifespan)
3232
app.include_router(user.router)
33-
app.include_router(schedule.router)
34-
app.include_router(send_email.router)
33+
# app.include_router(schedule.router)
34+
# app.include_router(send_email.router)
3535

3636

3737
@app.get("/")
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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

Comments
 (0)