|
| 1 | +from typing import Optional |
| 2 | +import uuid |
| 3 | + |
| 4 | +from sqlalchemy import Boolean, Column, ForeignKeyConstraint, Index, PrimaryKeyConstraint, String, Uuid |
| 5 | +from sqlmodel import Field, Relationship, SQLModel |
| 6 | + |
| 7 | +class Category(SQLModel, table=True): |
| 8 | + __table_args__ = ( |
| 9 | + PrimaryKeyConstraint('id', name='category_pkey'), |
| 10 | + ) |
| 11 | + |
| 12 | + name: str = Field(sa_column=Column('name', String(100), nullable=False)) |
| 13 | + id: uuid.UUID = Field(sa_column=Column('id', Uuid, primary_key=True)) |
| 14 | + created_at: str = Field(sa_column=Column('created_at', String, nullable=False)) |
| 15 | + description: Optional[str] = Field(default=None, sa_column=Column('description', String(500))) |
| 16 | + |
| 17 | + |
| 18 | +class User(SQLModel, table=True): |
| 19 | + __table_args__ = ( |
| 20 | + PrimaryKeyConstraint('id', name='user_pkey'), |
| 21 | + Index('ix_user_email', 'email', unique=True) |
| 22 | + ) |
| 23 | + |
| 24 | + email: str = Field(sa_column=Column('email', String(255), nullable=False)) |
| 25 | + is_active: bool = Field(sa_column=Column('is_active', Boolean, nullable=False)) |
| 26 | + is_superuser: bool = Field(sa_column=Column('is_superuser', Boolean, nullable=False)) |
| 27 | + hashed_password: str = Field(sa_column=Column('hashed_password', String, nullable=False)) |
| 28 | + id: uuid.UUID = Field(sa_column=Column('id', Uuid, primary_key=True)) |
| 29 | + full_name: Optional[str] = Field(default=None, sa_column=Column('full_name', String(255))) |
| 30 | + |
| 31 | + item: list['Item'] = Relationship(back_populates='owner') |
| 32 | + |
| 33 | + |
| 34 | +class Item(SQLModel, table=True): |
| 35 | + __table_args__ = ( |
| 36 | + ForeignKeyConstraint(['owner_id'], ['user.id'], ondelete='CASCADE', name='item_owner_id_fkey'), |
| 37 | + PrimaryKeyConstraint('id', name='item_pkey') |
| 38 | + ) |
| 39 | + |
| 40 | + title: str = Field(sa_column=Column('title', String(255), nullable=False)) |
| 41 | + id: uuid.UUID = Field(sa_column=Column('id', Uuid, primary_key=True)) |
| 42 | + owner_id: uuid.UUID = Field(sa_column=Column('owner_id', Uuid, nullable=False)) |
| 43 | + description: Optional[str] = Field(default=None, sa_column=Column('description', String(255))) |
| 44 | + |
| 45 | + owner: Optional['User'] = Relationship(back_populates='item') |
0 commit comments