POL-5: Add organizations table

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Dianaka123
2026-02-26 15:19:23 +03:00
parent 4c1870ebb4
commit d96d5560cf
2 changed files with 31 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
import uuid
from datetime import datetime
from sqlalchemy import Boolean, DateTime, ForeignKey, String, Uuid, func
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.database import Base
class Organization(Base):
__tablename__ = "organizations"
id: Mapped[uuid.UUID] = mapped_column(Uuid(as_uuid=True), primary_key=True, default=uuid.uuid4)
user_id: Mapped[uuid.UUID] = mapped_column(Uuid(as_uuid=True), ForeignKey("users.id", ondelete="CASCADE"), unique=True)
name: Mapped[str] = mapped_column(String(255), nullable=False)
instagram: Mapped[str | None] = mapped_column(String(100))
email: Mapped[str | None] = mapped_column(String(255))
city: Mapped[str | None] = mapped_column(String(100))
logo_url: Mapped[str | None] = mapped_column(String(500))
verified: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
# 'pending' | 'active' | 'rejected' | 'blocked'
status: Mapped[str] = mapped_column(String(20), nullable=False, default="pending")
block_reason: Mapped[str | None] = mapped_column(String(500))
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), onupdate=func.now()
)
user: Mapped["User"] = relationship(back_populates="organization") # type: ignore[name-defined]
championships: Mapped[list["Championship"]] = relationship(back_populates="organization") # type: ignore[name-defined]

View File

@@ -30,6 +30,7 @@ class User(Base):
refresh_tokens: Mapped[list["RefreshToken"]] = relationship(back_populates="user", cascade="all, delete-orphan")
registrations: Mapped[list["Registration"]] = relationship(back_populates="user") # type: ignore[name-defined]
notification_logs: Mapped[list["NotificationLog"]] = relationship(back_populates="user") # type: ignore[name-defined]
organization: Mapped["Organization | None"] = relationship(back_populates="user", uselist=False) # type: ignore[name-defined]
class RefreshToken(Base):