Initial monorepo structure
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
"""Association models."""
|
||||
|
||||
from sqlalchemy import Column, Integer, ForeignKey, String, Text
|
||||
from sqlalchemy.orm import relationship
|
||||
from app.models.base import Base, TimestampMixin
|
||||
|
||||
|
||||
class UserRole(Base, TimestampMixin):
|
||||
__tablename__ = "user_roles"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
user_id = Column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
|
||||
role_id = Column(Integer, ForeignKey("roles.id", ondelete="CASCADE"), nullable=False)
|
||||
|
||||
user = relationship("User", back_populates="user_roles")
|
||||
role = relationship("Role", back_populates="user_roles")
|
||||
|
||||
|
||||
class ModuleRole(Base, TimestampMixin):
|
||||
__tablename__ = "module_roles"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
module_id = Column(Integer, ForeignKey("modules.id", ondelete="CASCADE"), nullable=False)
|
||||
role_name = Column(String(100), nullable=False)
|
||||
description = Column(Text)
|
||||
|
||||
module = relationship("Module", back_populates="module_roles")
|
||||
user_module_roles = relationship("UserModuleRole", back_populates="module_role", cascade="all, delete-orphan")
|
||||
|
||||
|
||||
class UserModuleRole(Base, TimestampMixin):
|
||||
__tablename__ = "user_module_roles"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
user_id = Column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
|
||||
module_role_id = Column(Integer, ForeignKey("module_roles.id", ondelete="CASCADE"), nullable=False)
|
||||
|
||||
user = relationship("User", back_populates="user_module_roles")
|
||||
module_role = relationship("ModuleRole", back_populates="user_module_roles")
|
||||
Reference in New Issue
Block a user