tabletop-frog/src/ttfrog/db/schema/item.py

38 lines
1.1 KiB
Python
Raw Normal View History

2024-07-28 13:55:19 -07:00
from sqlalchemy import ForeignKey, String
from sqlalchemy.orm import Mapped, mapped_column
from ttfrog.db.base import BaseObject, EnumField
from ttfrog.db.schema.modifiers import ConditionMixin
__all__ = [
"Item",
"Spell",
]
class ItemType(EnumField):
ITEM = "ITEM"
SPELL = "SPELL"
class Item(BaseObject, ConditionMixin):
__tablename__ = "item"
__mapper_args__ = {
"polymorphic_identity": ItemType.ITEM,
"polymorphic_on": "item_type"
}
id: Mapped[int] = mapped_column(init=False, primary_key=True, autoincrement=True)
name: Mapped[str] = mapped_column(String(collation="NOCASE"), nullable=False, unique=True)
consumable: Mapped[bool] = mapped_column(default=False)
item_type: Mapped[ItemType] = mapped_column(default=ItemType.ITEM, nullable=False)
class Spell(Item):
__tablename__ = "spell"
__mapper_args__ = {
"polymorphic_identity": ItemType.SPELL
}
id: Mapped[int] = mapped_column(ForeignKey("item.id"), primary_key=True)
level: Mapped[int] = mapped_column(nullable=False, info={"min": 0, "max": 9}, default=0)
concentration: Mapped[bool] = mapped_column(default=False)