Skip to content

Commit

Permalink
Add skills to person
Browse files Browse the repository at this point in the history
  • Loading branch information
shrir committed Oct 21, 2024
1 parent 2ad0d7f commit 862fb2c
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# type: ignore
"""Add skills column to person
Revision ID: 1eb9c30637c2
Revises: 5fd2ebfc9eff
Create Date: 2024-10-21 18:04:45.665951+00:00
"""
from __future__ import annotations

import warnings
from typing import TYPE_CHECKING

import sqlalchemy as sa
from alembic import op
from advanced_alchemy.types import EncryptedString, EncryptedText, GUID, ORA_JSONB, DateTimeUTC
from sqlalchemy import Text # noqa: F401
from sqlalchemy.dialects import postgresql
if TYPE_CHECKING:
from collections.abc import Sequence

__all__ = ["downgrade", "upgrade", "schema_upgrades", "schema_downgrades", "data_upgrades", "data_downgrades"]

sa.GUID = GUID
sa.DateTimeUTC = DateTimeUTC
sa.ORA_JSONB = ORA_JSONB
sa.EncryptedString = EncryptedString
sa.EncryptedText = EncryptedText

# revision identifiers, used by Alembic.
revision = '1eb9c30637c2'
down_revision = '5fd2ebfc9eff'
branch_labels = None
depends_on = None


def upgrade() -> None:
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=UserWarning)
with op.get_context().autocommit_block():
schema_upgrades()
data_upgrades()

def downgrade() -> None:
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=UserWarning)
with op.get_context().autocommit_block():
data_downgrades()
schema_downgrades()

def schema_upgrades() -> None:
"""schema upgrade migrations go here."""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('person', schema=None) as batch_op:
batch_op.add_column(sa.Column('skills', postgresql.JSONB(astext_type=sa.Text()), nullable=True))

# ### end Alembic commands ###

def schema_downgrades() -> None:
"""schema downgrade migrations go here."""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('person', schema=None) as batch_op:
batch_op.drop_column('skills')

# ### end Alembic commands ###

def data_upgrades() -> None:
"""Add any optional data upgrade migrations here!"""

def data_downgrades() -> None:
"""Add any optional data downgrade migrations here!"""
1 change: 1 addition & 0 deletions src/app/db/models/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Person(UUIDAuditBase, SlugKey):
social_activities: Mapped[list[SocialActivity] | None] = mapped_column(
SocialActivityType, nullable=True, default=None
)
skills: Mapped[list[str] | None] = mapped_column(JSONB, nullable=True, default=None)
company_id: Mapped[UUID] = mapped_column(ForeignKey("company.id"), nullable=True, index=True)
# -----------
# ORM Relationships
Expand Down
1 change: 1 addition & 0 deletions src/app/domain/people/controllers/persons.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ async def create_person_from_url(
personal_numbers=person_details.get("personal_numbers", []),
birth_date=birth_date,
work_experiences=work_experiences,
skills=person_details.get("skills"),
company_id=company_db_obj.id,
)
db_obj = await persons_service.upsert(obj.to_dict(), item_id=results[0].id if count > 0 else None)
Expand Down
3 changes: 3 additions & 0 deletions src/app/domain/people/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Person(CamelizedBaseStruct):
languages: list[str] | None = None
work_experiences: list[WorkExperience] | None = None
social_activities: list[SocialActivity] | None = None
skills: list[str] | None = None


class PersonCreate(CamelizedBaseStruct):
Expand Down Expand Up @@ -65,6 +66,7 @@ class PersonCreate(CamelizedBaseStruct):
languages: list[str] | None = None
work_experiences: list[WorkExperience] | None = None
social_activities: list[SocialActivity] | None = None
skills: list[str] | None = None
company_id: str | None = None


Expand Down Expand Up @@ -100,3 +102,4 @@ class PersonUpdate(CamelizedBaseStruct, omit_defaults=True):
languages: list[str] | None | msgspec.UnsetType = msgspec.UNSET
work_experiences: list[WorkExperience] | None | msgspec.UnsetType = msgspec.UNSET
social_activities: list[SocialActivity] | None | msgspec.UnsetType = msgspec.UNSET
skills: list[str] | None | msgspec.UnsetType = msgspec.UNSET

0 comments on commit 862fb2c

Please sign in to comment.