diff --git a/src/app/db/migrations/versions/2024-08-27_remove_profile_pic_url_field_from__6eb23ec2feaa.py b/src/app/db/migrations/versions/2024-08-27_remove_profile_pic_url_field_from__6eb23ec2feaa.py new file mode 100644 index 00000000..3ee6d09c --- /dev/null +++ b/src/app/db/migrations/versions/2024-08-27_remove_profile_pic_url_field_from__6eb23ec2feaa.py @@ -0,0 +1,71 @@ +# type: ignore +"""Remove profile_pic_url field from company + +Revision ID: 6eb23ec2feaa +Revises: 0d39d07c03b2 +Create Date: 2024-08-27 12:30:28.711529+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 + +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 = '6eb23ec2feaa' +down_revision = '0d39d07c03b2' +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('company', schema=None) as batch_op: + batch_op.drop_column('profile_pic_url') + + # ### end Alembic commands ### + +def schema_downgrades() -> None: + """schema downgrade migrations go here.""" + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('company', schema=None) as batch_op: + batch_op.add_column(sa.Column('profile_pic_url', sa.VARCHAR(), autoincrement=False, nullable=True)) + + # ### 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/company.py b/src/app/db/models/company.py index 3a35d34d..c9911bfe 100644 --- a/src/app/db/models/company.py +++ b/src/app/db/models/company.py @@ -33,7 +33,6 @@ class Company(UUIDAuditBase, SlugKey): headcount: Mapped[int | None] = mapped_column(nullable=True, default=None, index=True) founded_year: Mapped[int | None] = mapped_column(nullable=True, default=None) url: Mapped[str | None] = mapped_column(String(length=2083), nullable=True, default=None) - profile_pic_url: Mapped[str | None] = mapped_column(String(length=2083), nullable=True, default=None) linkedin_profile_url: Mapped[str | None] = mapped_column(String(length=2083), nullable=True, default=None) hq_location: Mapped[Location | None] = mapped_column(LocationType, nullable=True, default=None) last_funding: Mapped[Funding | None] = mapped_column(FundingType, nullable=True, default=None) diff --git a/src/app/domain/companies/schemas.py b/src/app/domain/companies/schemas.py index ff47acb3..4b602542 100644 --- a/src/app/domain/companies/schemas.py +++ b/src/app/domain/companies/schemas.py @@ -7,6 +7,7 @@ from app.db.models.company import Company from app.lib.schema import CamelizedBaseStruct, Location, Funding, OrgSize +from app.lib.utils import get_logo_dev_link class Company(CamelizedBaseStruct): @@ -29,6 +30,17 @@ class Company(CamelizedBaseStruct): last_funding: Funding | None = None org_size: OrgSize | None = None + @classmethod + def from_dict(cls, data): + """Create an instance from a dictionary.""" + obj = cls(**data) + + # Add company logo URL + if obj.url: + obj.profile_pic_url = get_logo_dev_link(obj.url) + + return obj + class CompanyCreate(CamelizedBaseStruct): """A company create schema.""" @@ -40,7 +52,6 @@ class CompanyCreate(CamelizedBaseStruct): headcount: int | None = None founded_year: int | None = None url: str | None = None - profile_pic_url: str | None = None linkedin_profile_url: str | None = None hq_location: Location | None = None last_funding: Funding | None = None @@ -57,7 +68,6 @@ class CompanyUpdate(CamelizedBaseStruct, omit_defaults=True): headcount: int | None | msgspec.UnsetType = msgspec.UNSET founded_year: int | None | msgspec.UnsetType = msgspec.UNSET url: str | None | msgspec.UnsetType = msgspec.UNSET - profile_pic_url: str | None | msgspec.UnsetType = msgspec.UNSET linkedin_profile_url: str | None | msgspec.UnsetType = msgspec.UNSET hq_location: Location | None | msgspec.UnsetType = msgspec.UNSET last_funding: Funding | None | msgspec.UnsetType = msgspec.UNSET