Consistently use DEFAULT_PK_TYPE

This commit is contained in:
Daniil Fajnberg 2022-08-17 15:03:41 +02:00
parent 284986f763
commit 8cd13d8337
3 changed files with 20 additions and 20 deletions

View File

@ -13,7 +13,7 @@ from sqlalchemy_utils.types import CountryType
from sqlmodel.main import Field, Relationship
from compub.utils import multi_max
from .base import AbstractBase
from .base import AbstractBase, DEFAULT_PK_TYPE as PK
from .geography import Address
@ -55,7 +55,7 @@ class LegalFormSubcategory(AbstractBase, table=True):
name: Optional[str] = Field(default=None, max_length=255, sa_column=Column(Unicode(255)))
# Relationships
legal_form_id: Optional[int] = Field(
legal_form_id: Optional[PK] = Field(
foreign_key='legal_form.id', default=None, nullable=False, index=True
)
legal_form: Optional[LegalForm] = Relationship(
@ -77,8 +77,8 @@ class CompanyIndustryLink(AbstractBase, table=True):
)
# Relationships
company_id: Optional[int] = Field(foreign_key='company.id', default=None, nullable=False, primary_key=True)
industry_id: Optional[int] = Field(foreign_key='industry.id', default=None, nullable=False, primary_key=True)
company_id: Optional[PK] = Field(foreign_key='company.id', default=None, nullable=False, primary_key=True)
industry_id: Optional[PK] = Field(foreign_key='industry.id', default=None, nullable=False, primary_key=True)
class CompanyExecutiveLink(AbstractBase, table=True):
@ -88,8 +88,8 @@ class CompanyExecutiveLink(AbstractBase, table=True):
)
# Relationships
company_id: Optional[int] = Field(foreign_key='company.id', default=None, nullable=False, primary_key=True)
executive_id: Optional[int] = Field(foreign_key='executive.id', default=None, nullable=False, primary_key=True)
company_id: Optional[PK] = Field(foreign_key='company.id', default=None, nullable=False, primary_key=True)
executive_id: Optional[PK] = Field(foreign_key='executive.id', default=None, nullable=False, primary_key=True)
class Industry(AbstractBase, table=True):
@ -137,14 +137,14 @@ class Company(AbstractBase, table=True):
city: Optional[str] = Field(max_length=255, nullable=True, index=True)
# Relationships
legal_form_id: Optional[int] = Field(
legal_form_id: Optional[PK] = Field(
foreign_key='legal_form_subcategory.id', default=None, index=True
)
legal_form: Optional[LegalFormSubcategory] = Relationship(
back_populates='companies', sa_relationship_kwargs={'lazy': 'selectin'}
)
address_id: Optional[int] = Field(
address_id: Optional[PK] = Field(
foreign_key='address.id', default=None, index=True
)
address: Optional[Address] = Relationship(
@ -188,7 +188,7 @@ class CompanyName(AbstractBase, table=True):
slug: Optional[str] = Field(default=None, max_length=__MAX_SLUG_LENGTH__, index=True)
# Relationships
company_id: Optional[int] = Field(
company_id: Optional[PK] = Field(
foreign_key='company.id', default=None, nullable=False, index=True
)
company: Optional[Company] = Relationship(

View File

@ -4,7 +4,7 @@ from sqlalchemy.sql.schema import Column, Index
from sqlalchemy.sql.sqltypes import Unicode
from sqlmodel.main import Field, Relationship
from .base import AbstractBase, DEFAULT_PK_TYPE
from .base import AbstractBase, DEFAULT_PK_TYPE as PK
from .geography import StateProvince, Address
@ -32,10 +32,10 @@ class CourtDepartmentCourtLink(AbstractBase, table=True):
)
# Relationships
court_department_id: Optional[DEFAULT_PK_TYPE] = Field(
court_department_id: Optional[PK] = Field(
foreign_key='court_department.id', default=None, nullable=False, primary_key=True
)
court_id: Optional[DEFAULT_PK_TYPE] = Field(
court_id: Optional[PK] = Field(
foreign_key='court.id', default=None, nullable=False, primary_key=True
)
@ -67,28 +67,28 @@ class Court(AbstractBase, table=True):
name: str = Field(max_length=255, sa_column=Column(Unicode(255)))
# Relationships
court_class_id: Optional[DEFAULT_PK_TYPE] = Field(
court_class_id: Optional[PK] = Field(
foreign_key='court_class.id', default=None, nullable=False, index=True
)
court_class: Optional[CourtClass] = Relationship(
back_populates='courts', sa_relationship_kwargs={'lazy': 'selectin'}
)
state_province_id: Optional[DEFAULT_PK_TYPE] = Field(
state_province_id: Optional[PK] = Field(
foreign_key='state_province.id', default=None, nullable=True, index=True
)
state_province: Optional[StateProvince] = Relationship(
back_populates='courts', sa_relationship_kwargs={'lazy': 'selectin'}
)
address_id: Optional[DEFAULT_PK_TYPE] = Field(
address_id: Optional[PK] = Field(
foreign_key='address.id', default=None, nullable=True, index=True
)
address: Optional[Address] = Relationship(
back_populates='courts', sa_relationship_kwargs={'lazy': 'selectin'}
)
parent_court_id: Optional[DEFAULT_PK_TYPE] = Field(
parent_court_id: Optional[PK] = Field(
foreign_key='court.id', default=None, nullable=True, index=True
)
parent_court: Optional['Court'] = Relationship(

View File

@ -7,7 +7,7 @@ from sqlalchemy_utils.primitives.country import Country
from sqlalchemy_utils.types import CountryType
from sqlmodel.main import Field, Relationship
from .base import AbstractBase
from .base import AbstractBase, DEFAULT_PK_TYPE as PK
if TYPE_CHECKING:
from .companies import Company
@ -61,7 +61,7 @@ class City(AbstractBase, table=True):
name: str = Field(max_length=255, sa_column=Column(Unicode(255), nullable=False, index=True))
# Relationships
state_province_id: Optional[int] = Field(
state_province_id: Optional[PK] = Field(
foreign_key='state_province.id', default=None, nullable=False, index=True
)
state_province: Optional[StateProvince] = Relationship(
@ -80,7 +80,7 @@ class Street(AbstractBase, table=True):
name: str = Field(max_length=255, sa_column=Column(Unicode(255), nullable=False, index=True))
# Relationships
city_id: Optional[int] = Field(
city_id: Optional[PK] = Field(
foreign_key='city.id', default=None, nullable=False, index=True
)
city: Optional[City] = Relationship(
@ -100,7 +100,7 @@ class Address(AbstractBase, table=True):
supplement: str = Field(max_length=255)
# Relationships
street_id: Optional[int] = Field(
street_id: Optional[PK] = Field(
foreign_key='street.id', default=None, nullable=False, index=True
)
street: Optional[Street] = Relationship(