fix foreign keys

This commit is contained in:
Jacob Windsor 2025-02-19 16:21:39 +01:00
parent 47724059bd
commit ed6c49a1b7
5 changed files with 9 additions and 13 deletions

View File

@ -16,10 +16,6 @@ start:
docker compose down -v db docker compose down -v db
docker compose up --build docker compose up --build
clean-db:
docker compose down
docker compose down -v db
clean: clean:
rm -rf $(VENV_DIR) rm -rf $(VENV_DIR)

View File

@ -1,9 +1,9 @@
from pydantic import BaseModel from pydantic import BaseModel, Field
class HouseCreateRequest(BaseModel): class HouseCreateRequest(BaseModel):
address: str address: str = Field(..., min_length=1, max_length=255, description="House address", examples=["123 Main St"])
city: str city: str = Field(..., description="City where the house is located", examples=["Springfield"])
country: str country: str = Field(..., description="Country where the house is located", examples=["USA"])
price: float price: float = Field(..., description="Price of the house", examples=[250000.00])
description: str description: str = Field(..., description="Description of the house", examples=["A beautiful 3-bedroom house"])

View File

@ -8,4 +8,4 @@ class House(SQLModel, table=True):
country: str = Field() country: str = Field()
price: float = Field() price: float = Field()
description: str = Field() description: str = Field()
owner_id: UUID = Field(foreign_key="owner.id") owner_user_id: UUID = Field(foreign_key="owner.user_id")

View File

@ -3,4 +3,4 @@ from uuid import uuid4, UUID
class Owner(SQLModel, table=True): class Owner(SQLModel, table=True):
id: UUID = Field(default_factory=uuid4, primary_key=True) id: UUID = Field(default_factory=uuid4, primary_key=True)
user_id: UUID = Field(foreign_key="user.id") user_id: UUID = Field(foreign_key="user.id", unique=True)

View File

@ -23,7 +23,7 @@ async def create_house(body: HouseCreateRequest, auth: Annotated[AuthContext, De
await owner_repository.save(new_owner) await owner_repository.save(new_owner)
house = House( house = House(
owner_id=auth.user.id, owner_user_id=auth.user.id,
address=body.address, address=body.address,
city=body.city, city=body.city,
country=body.country, country=body.country,