reset alembic

This commit is contained in:
Jakub Miazek
2024-01-02 21:14:38 +01:00
parent d2c17a21d4
commit 51aa79788b
3 changed files with 49 additions and 52 deletions

View File

@@ -1,12 +1,13 @@
import uuid
from fastapi import HTTPException, status
from sqlalchemy import String, select
from sqlalchemy import String, select, ForeignKey
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import mapped_column, Mapped
from sqlalchemy.orm import mapped_column, Mapped, relationship, joinedload
from app.models.base import Base
from app.models.nonsense import Nonsense
class Stuff(Base):
@@ -16,6 +17,8 @@ class Stuff(Base):
name: Mapped[str] = mapped_column(String, primary_key=True, unique=True)
description: Mapped[str | None]
nonsense: Mapped["Nonsense"] = relationship("Nonsense", secondary="happy_hog.stuff_full_of_nonsense")
@classmethod
async def find(cls, db_session: AsyncSession, name: str):
"""
@@ -24,7 +27,11 @@ class Stuff(Base):
:param name:
:return:
"""
stmt = select(cls).where(cls.name == name)
stmt = (
select(cls)
.options(joinedload(cls.nonsense))
.where(cls.name == name)
)
result = await db_session.execute(stmt)
instance = result.scalars().first()
if instance is None:
@@ -34,3 +41,12 @@ class Stuff(Base):
)
else:
return instance
class StuffFullOfNonsense(Base):
__tablename__ = "stuff_full_of_nonsense"
__table_args__ = ({"schema": "happy_hog"},)
id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), default=uuid.uuid4, primary_key=True)
stuff_id: Mapped[Stuff] = mapped_column(UUID, ForeignKey("happy_hog.stuff.id"))
nonsense_id: Mapped["Nonsense"] = mapped_column(UUID, ForeignKey("happy_hog.nonsense.id"))
but_why: Mapped[str | None]