Restructure into full project layout
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
from app.models.user import User, UserRole
|
||||
from app.models.deck import Deck, DeckCard, DeckMode, CardSlot
|
||||
from app.models.collection import CollectionCard
|
||||
@@ -0,0 +1,21 @@
|
||||
from sqlalchemy import String, Integer, ForeignKey, JSON, UniqueConstraint
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
from app.core.database import Base
|
||||
|
||||
|
||||
class CollectionCard(Base):
|
||||
__tablename__ = "user_collection"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
owner_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True)
|
||||
card_name: Mapped[str] = mapped_column(String(200), nullable=False)
|
||||
set_code: Mapped[str] = mapped_column(String(10), nullable=False, default="")
|
||||
collector_number: Mapped[str] = mapped_column(String(20), nullable=False, default="")
|
||||
quantity: Mapped[int] = mapped_column(Integer, default=0)
|
||||
foil_quantity: Mapped[int] = mapped_column(Integer, default=0)
|
||||
scryfall_id: Mapped[str] = mapped_column(String(36), nullable=False, default="")
|
||||
scryfall_data: Mapped[dict | None] = mapped_column(JSON)
|
||||
|
||||
__table_args__ = (
|
||||
UniqueConstraint("owner_id", "scryfall_id", name="uq_owner_scryfall"),
|
||||
)
|
||||
@@ -0,0 +1,56 @@
|
||||
import enum
|
||||
from datetime import datetime
|
||||
from sqlalchemy import String, Boolean, Enum, DateTime, Integer, Float, ForeignKey, JSON, Text
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
from app.core.database import Base
|
||||
|
||||
|
||||
class DeckMode(str, enum.Enum):
|
||||
GENERATE = "generate"
|
||||
COMPLETE = "complete"
|
||||
CULL = "cull"
|
||||
|
||||
|
||||
class CardSlot(str, enum.Enum):
|
||||
CREATURE = "creature"
|
||||
INSTANT = "instant"
|
||||
SORCERY = "sorcery"
|
||||
ENCHANTMENT = "enchantment"
|
||||
ARTIFACT = "artifact"
|
||||
PLANESWALKER = "planeswalker"
|
||||
LAND = "land"
|
||||
BATTLE = "battle"
|
||||
|
||||
|
||||
class Deck(Base):
|
||||
__tablename__ = "decks"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
owner_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True)
|
||||
name: Mapped[str] = mapped_column(String(200), nullable=False)
|
||||
commander: Mapped[str] = mapped_column(String(200), nullable=False)
|
||||
description: Mapped[str | None] = mapped_column(Text)
|
||||
mode: Mapped[DeckMode] = mapped_column(Enum(DeckMode), nullable=False)
|
||||
playstyle: Mapped[str | None] = mapped_column(String(100))
|
||||
prefer_owned: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
budget_enabled: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
budget_amount: Mapped[float | None] = mapped_column(Float)
|
||||
budget_scope: Mapped[str] = mapped_column(String(20), default="purchase")
|
||||
ai_reasoning: Mapped[dict | None] = mapped_column(JSON)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
|
||||
class DeckCard(Base):
|
||||
__tablename__ = "deck_cards"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
deck_id: Mapped[int] = mapped_column(ForeignKey("decks.id", ondelete="CASCADE"), nullable=False, index=True)
|
||||
scryfall_id: Mapped[str] = mapped_column(String(36), nullable=False)
|
||||
card_name: Mapped[str] = mapped_column(String(200), nullable=False)
|
||||
slot: Mapped[CardSlot] = mapped_column(Enum(CardSlot), nullable=False)
|
||||
quantity: Mapped[int] = mapped_column(Integer, default=1)
|
||||
is_owned: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
is_commander: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
ai_reasoning: Mapped[str | None] = mapped_column(Text)
|
||||
scryfall_data: Mapped[dict | None] = mapped_column(JSON)
|
||||
@@ -0,0 +1,24 @@
|
||||
import enum
|
||||
from datetime import datetime
|
||||
from sqlalchemy import String, Boolean, Enum, DateTime
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
from app.core.database import Base
|
||||
|
||||
|
||||
class UserRole(str, enum.Enum):
|
||||
PENDING = "pending"
|
||||
APPROVED = "approved"
|
||||
ADMIN = "admin"
|
||||
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = "users"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
email: Mapped[str] = mapped_column(String(255), unique=True, nullable=False, index=True)
|
||||
hashed_password: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
display_name: Mapped[str | None] = mapped_column(String(100))
|
||||
role: Mapped[UserRole] = mapped_column(Enum(UserRole), default=UserRole.PENDING, nullable=False)
|
||||
is_active: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False)
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
|
||||
Reference in New Issue
Block a user