From 862fb2c6abc2560dca113913151ca73453b7e267 Mon Sep 17 00:00:00 2001 From: shri Date: Mon, 21 Oct 2024 20:05:31 +0200 Subject: [PATCH] Add skills to person --- ...dd_skills_column_to_person_1eb9c30637c2.py | 71 +++++++++++++++++++ src/app/db/models/person.py | 1 + src/app/domain/people/controllers/persons.py | 1 + src/app/domain/people/schemas.py | 3 + 4 files changed, 76 insertions(+) create mode 100644 src/app/db/migrations/versions/2024-10-21_add_skills_column_to_person_1eb9c30637c2.py diff --git a/src/app/db/migrations/versions/2024-10-21_add_skills_column_to_person_1eb9c30637c2.py b/src/app/db/migrations/versions/2024-10-21_add_skills_column_to_person_1eb9c30637c2.py new file mode 100644 index 00000000..db4adf5e --- /dev/null +++ b/src/app/db/migrations/versions/2024-10-21_add_skills_column_to_person_1eb9c30637c2.py @@ -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!""" diff --git a/src/app/db/models/person.py b/src/app/db/models/person.py index 5479b1d1..1daa3b7e 100644 --- a/src/app/db/models/person.py +++ b/src/app/db/models/person.py @@ -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 diff --git a/src/app/domain/people/controllers/persons.py b/src/app/domain/people/controllers/persons.py index 28aafb8d..572f6367 100644 --- a/src/app/domain/people/controllers/persons.py +++ b/src/app/domain/people/controllers/persons.py @@ -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) diff --git a/src/app/domain/people/schemas.py b/src/app/domain/people/schemas.py index b5128b86..817add05 100644 --- a/src/app/domain/people/schemas.py +++ b/src/app/domain/people/schemas.py @@ -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): @@ -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 @@ -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