41 lines
1.6 KiB
Python
41 lines
1.6 KiB
Python
"""Organization model."""
|
|
from datetime import datetime
|
|
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Enum, Text
|
|
from sqlalchemy.orm import relationship
|
|
from app.core.database import Base
|
|
import enum
|
|
|
|
class MemberRole(str, enum.Enum):
|
|
VIEWER = "viewer"
|
|
ANALYST = "analyst"
|
|
MANAGER = "manager"
|
|
ADMIN = "admin"
|
|
OWNER = "owner"
|
|
|
|
class Organization(Base):
|
|
__tablename__ = "organizations"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
name = Column(String(255), nullable=False)
|
|
slug = Column(String(100), unique=True, nullable=False, index=True)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
|
|
# Relations
|
|
members = relationship("OrganizationMember", back_populates="organization", cascade="all, delete-orphan")
|
|
integrations = relationship("Integration", back_populates="organization", cascade="all, delete-orphan")
|
|
issues = relationship("Issue", back_populates="organization", cascade="all, delete-orphan")
|
|
audit_logs = relationship("AuditLog", back_populates="organization")
|
|
|
|
class OrganizationMember(Base):
|
|
__tablename__ = "organization_members"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
organization_id = Column(Integer, ForeignKey("organizations.id"), nullable=False)
|
|
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
|
role = Column(Enum(MemberRole), default=MemberRole.VIEWER)
|
|
joined_at = Column(DateTime, default=datetime.utcnow)
|
|
|
|
# Relations
|
|
organization = relationship("Organization", back_populates="members")
|
|
user = relationship("User", back_populates="memberships")
|