Skip to content

Commit

Permalink
db: Add column to journey history table
Browse files Browse the repository at this point in the history
In order to calculate and store the total amounts of vacation and hours expected in a year, we need a column in which to store that information. This migration adds the necessary column.
  • Loading branch information
dmtrek14 committed Jan 5, 2024
1 parent c26722a commit 097107e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
4 changes: 3 additions & 1 deletion api/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ async def get_current_user(token: Annotated[str, Depends(oauth2_scheme)], db: Se
capacities=[],
)
for c in user_in_db.capacities:
cap = UserCapacity(capacity=c.capacity, start=c.start, end=c.end, is_current=c.is_current)
cap = UserCapacity(
capacity=c.capacity, start=c.start, end=c.end, is_current=c.is_current, aggregates=c.aggregates
)
user.capacities.append(cap)

if USE_OIDC_ROLES:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Add column to journey history
Revision ID: 2ac6108453f3
Revises: 2795e5409fb5
Create Date: 2024-01-05 10:07:17.850610
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '2ac6108453f3'
down_revision = '2795e5409fb5'
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("journey_history", sa.Column("aggregates", postgresql.JSONB(), nullable=True))
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("journey_history", "aggregates")
# ### end Alembic commands ###
2 changes: 2 additions & 0 deletions api/models/user.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import List
from sqlalchemy import Date, Column, ForeignKey, Integer, String, Numeric, UniqueConstraint, CheckConstraint
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.orm import relationship, Mapped, mapped_column
from sqlalchemy.ext.hybrid import hybrid_property
from db.base_class import Base
Expand Down Expand Up @@ -69,6 +70,7 @@ class UserCapacity(Base):
start = Column("init_date", Date, nullable=False)
end = Column("end_date", Date, nullable=True)
user_id = Column("usrid", Integer, ForeignKey("usr.id"), nullable=False)
aggregates = Column("aggregates", JSONB, nullable=True)

@hybrid_property
def is_current(self):
Expand Down

0 comments on commit 097107e

Please sign in to comment.