Skip to content

Commit

Permalink
Remove pic_profile_url from company table but populate in the schema …
Browse files Browse the repository at this point in the history
…from domain using logo.dev service
  • Loading branch information
shri committed Aug 27, 2024
1 parent 2dac7a6 commit bebec1f
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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!"""
1 change: 0 additions & 1 deletion src/app/db/models/company.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 12 additions & 2 deletions src/app/domain/companies/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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."""
Expand All @@ -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
Expand All @@ -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

0 comments on commit bebec1f

Please sign in to comment.