48 lines
1.0 KiB
Python
48 lines
1.0 KiB
Python
import uuid
|
|
from enum import Enum
|
|
|
|
from sqlalchemy import String, Boolean, ForeignKey, Enum as SQLEnum
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from db.base import Base
|
|
|
|
class GroupType(str, Enum):
|
|
GROUP = "group"
|
|
DIRECT = "direct"
|
|
|
|
|
|
|
|
class Group(Base):
|
|
__tablename__ = "groups" # type: ignore
|
|
|
|
name: Mapped[str] = mapped_column(
|
|
String(100),
|
|
nullable=False,
|
|
index=True
|
|
)
|
|
|
|
type: Mapped[GroupType] = mapped_column(
|
|
SQLEnum(GroupType, name="group_type"),
|
|
default=GroupType.GROUP,
|
|
nullable=False
|
|
)
|
|
|
|
is_active: Mapped[bool] = mapped_column(
|
|
Boolean,
|
|
default=True,
|
|
index=True
|
|
)
|
|
|
|
|
|
class GroupMember(Base):
|
|
__tablename__ = "group_members" # type: ignore
|
|
|
|
user_id: Mapped[uuid.UUID] = mapped_column(
|
|
ForeignKey("users.id", ondelete="CASCADE"),
|
|
index=True
|
|
)
|
|
|
|
group_id: Mapped[uuid.UUID] = mapped_column(
|
|
ForeignKey("groups.id", ondelete="CASCADE"),
|
|
index=True
|
|
) |