34 lines
1.4 KiB
Python
34 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import BigInteger, DateTime, ForeignKey, String
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.models.base import Base, TimestampMixin
|
|
|
|
|
|
class Role(Base, TimestampMixin):
|
|
__tablename__ = "sys_role"
|
|
|
|
id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
|
|
code: Mapped[str] = mapped_column(String(50), unique=True, index=True, nullable=False)
|
|
name: Mapped[str] = mapped_column(String(50), nullable=False)
|
|
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
|
|
|
admins: Mapped[list["Admin"]] = relationship("Admin", back_populates="role")
|
|
|
|
|
|
class Admin(Base, TimestampMixin):
|
|
__tablename__ = "sys_admin"
|
|
|
|
id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
|
|
username: Mapped[str] = mapped_column(String(50), unique=True, index=True, nullable=False)
|
|
password: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
name: Mapped[str] = mapped_column(String(50), nullable=False)
|
|
role_id: Mapped[int | None] = mapped_column(ForeignKey("sys_role.id"), nullable=True)
|
|
status: Mapped[int] = mapped_column(default=1, nullable=False)
|
|
last_login_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
|
|
|
role: Mapped[Role | None] = relationship("Role", back_populates="admins")
|