fix: use python 3.9 compatible sqlalchemy annotations
This commit is contained in:
@@ -2,6 +2,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from sqlalchemy import Boolean, DateTime, Enum as SAEnum, Float, ForeignKey, Integer, String, Text, UniqueConstraint
|
from sqlalchemy import Boolean, DateTime, Enum as SAEnum, Float, ForeignKey, Integer, String, Text, UniqueConstraint
|
||||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||||
@@ -29,9 +30,9 @@ class Employee(Base):
|
|||||||
|
|
||||||
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||||
name: Mapped[str] = mapped_column(String(200))
|
name: Mapped[str] = mapped_column(String(200))
|
||||||
portal_user_id: Mapped[str | None] = mapped_column(String(100), unique=True, index=True, nullable=True)
|
portal_user_id: Mapped[Optional[str]] = mapped_column(String(100), unique=True, index=True, nullable=True)
|
||||||
tg_chat_id: Mapped[str | None] = mapped_column(String(64), unique=True, nullable=True)
|
tg_chat_id: Mapped[Optional[str]] = mapped_column(String(64), unique=True, nullable=True)
|
||||||
tg_username: Mapped[str | None] = mapped_column(String(200), nullable=True)
|
tg_username: Mapped[Optional[str]] = mapped_column(String(200), nullable=True)
|
||||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||||
|
|
||||||
projects: Mapped[list["Project"]] = relationship(back_populates="owner")
|
projects: Mapped[list["Project"]] = relationship(back_populates="owner")
|
||||||
@@ -45,21 +46,21 @@ class Project(Base):
|
|||||||
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||||
title: Mapped[str] = mapped_column(String(300))
|
title: Mapped[str] = mapped_column(String(300))
|
||||||
deal_type: Mapped[DealType] = mapped_column(SAEnum(DealType))
|
deal_type: Mapped[DealType] = mapped_column(SAEnum(DealType))
|
||||||
our_price: Mapped[float | None] = mapped_column(Float, nullable=True)
|
our_price: Mapped[Optional[float]] = mapped_column(Float, nullable=True)
|
||||||
notes: Mapped[str | None] = mapped_column(Text, nullable=True)
|
notes: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||||||
|
|
||||||
# Опциональные параметры — используются для подсказок похожих объявлений
|
# Опциональные параметры — используются для подсказок похожих объявлений
|
||||||
dld_permit: Mapped[str | None] = mapped_column(String(100), index=True, nullable=True)
|
dld_permit: Mapped[Optional[str]] = mapped_column(String(100), index=True, nullable=True)
|
||||||
building: Mapped[str | None] = mapped_column(String(300), nullable=True)
|
building: Mapped[Optional[str]] = mapped_column(String(300), nullable=True)
|
||||||
bedrooms: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
bedrooms: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)
|
||||||
size_sqft: Mapped[float | None] = mapped_column(Float, nullable=True)
|
size_sqft: Mapped[Optional[float]] = mapped_column(Float, nullable=True)
|
||||||
our_url: Mapped[str | None] = mapped_column(Text, nullable=True)
|
our_url: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||||||
|
|
||||||
owner_id: Mapped[int] = mapped_column(ForeignKey("employees.id"))
|
owner_id: Mapped[int] = mapped_column(ForeignKey("employees.id"))
|
||||||
owner: Mapped[Employee] = relationship(back_populates="projects")
|
owner: Mapped[Employee] = relationship(back_populates="projects")
|
||||||
|
|
||||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||||
last_checked_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
last_checked_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
|
||||||
|
|
||||||
listings: Mapped[list["CompetitorListing"]] = relationship(
|
listings: Mapped[list["CompetitorListing"]] = relationship(
|
||||||
back_populates="project", cascade="all, delete-orphan"
|
back_populates="project", cascade="all, delete-orphan"
|
||||||
@@ -79,15 +80,15 @@ class CompetitorListing(Base):
|
|||||||
source: Mapped[Source] = mapped_column(SAEnum(Source))
|
source: Mapped[Source] = mapped_column(SAEnum(Source))
|
||||||
external_id: Mapped[str] = mapped_column(String(100)) # ID на стороне PF/Bayut
|
external_id: Mapped[str] = mapped_column(String(100)) # ID на стороне PF/Bayut
|
||||||
url: Mapped[str] = mapped_column(Text)
|
url: Mapped[str] = mapped_column(Text)
|
||||||
title: Mapped[str | None] = mapped_column(String(500), nullable=True)
|
title: Mapped[Optional[str]] = mapped_column(String(500), nullable=True)
|
||||||
agent_name: Mapped[str | None] = mapped_column(String(300), nullable=True)
|
agent_name: Mapped[Optional[str]] = mapped_column(String(300), nullable=True)
|
||||||
agency_name: Mapped[str | None] = mapped_column(String(300), nullable=True)
|
agency_name: Mapped[Optional[str]] = mapped_column(String(300), nullable=True)
|
||||||
permit_number: Mapped[str | None] = mapped_column(String(100), nullable=True)
|
permit_number: Mapped[Optional[str]] = mapped_column(String(100), nullable=True)
|
||||||
auto_discovered: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
|
auto_discovered: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
|
||||||
permit_missing_checks: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
|
permit_missing_checks: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
|
||||||
|
|
||||||
current_price: Mapped[float | None] = mapped_column(Float, nullable=True)
|
current_price: Mapped[Optional[float]] = mapped_column(Float, nullable=True)
|
||||||
currency: Mapped[str | None] = mapped_column(String(10), nullable=True, default="AED")
|
currency: Mapped[Optional[str]] = mapped_column(String(10), nullable=True, default="AED")
|
||||||
status: Mapped[ListingStatus] = mapped_column(SAEnum(ListingStatus), default=ListingStatus.ACTIVE)
|
status: Mapped[ListingStatus] = mapped_column(SAEnum(ListingStatus), default=ListingStatus.ACTIVE)
|
||||||
|
|
||||||
first_seen_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
first_seen_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||||
@@ -105,5 +106,5 @@ class PriceHistory(Base):
|
|||||||
listing_id: Mapped[int] = mapped_column(ForeignKey("competitor_listings.id"))
|
listing_id: Mapped[int] = mapped_column(ForeignKey("competitor_listings.id"))
|
||||||
listing: Mapped[CompetitorListing] = relationship(back_populates="price_history")
|
listing: Mapped[CompetitorListing] = relationship(back_populates="price_history")
|
||||||
|
|
||||||
price: Mapped[float | None] = mapped_column(Float, nullable=True)
|
price: Mapped[Optional[float]] = mapped_column(Float, nullable=True)
|
||||||
recorded_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
recorded_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||||
|
|||||||
Reference in New Issue
Block a user