first commit
This commit is contained in:
1
backend/app/models/__init__.py
Normal file
1
backend/app/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from app.core.db import Base
|
||||
31
backend/app/models/dashboard.py
Normal file
31
backend/app/models/dashboard.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from sqlalchemy import String, Boolean, Integer, ForeignKey, Text
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.core.db import Base
|
||||
|
||||
class Permission(Base):
|
||||
__tablename__ = "permissions"
|
||||
user_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"), primary_key=True)
|
||||
router_id: Mapped[int] = mapped_column(ForeignKey("routers.id", ondelete="CASCADE"), primary_key=True)
|
||||
can_view: Mapped[bool] = mapped_column(Boolean, default=True)
|
||||
can_edit: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
|
||||
class Dashboard(Base):
|
||||
__tablename__ = "dashboards"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
owner_user_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"), index=True)
|
||||
name: Mapped[str] = mapped_column(String(200))
|
||||
is_shared: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
|
||||
class DashboardPanel(Base):
|
||||
__tablename__ = "dashboard_panels"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
dashboard_id: Mapped[int] = mapped_column(ForeignKey("dashboards.id", ondelete="CASCADE"), index=True)
|
||||
title: Mapped[str] = mapped_column(String(200))
|
||||
router_id: Mapped[int] = mapped_column(ForeignKey("routers.id", ondelete="CASCADE"), index=True)
|
||||
# config_json: {"interfaces":["ether1"],"metrics":["rx_bps","tx_bps"],"interval_ms":1000,"window":120}
|
||||
config_json: Mapped[str] = mapped_column(Text, default="{}")
|
||||
|
||||
dashboard = relationship("Dashboard")
|
||||
41
backend/app/models/router.py
Normal file
41
backend/app/models/router.py
Normal file
@@ -0,0 +1,41 @@
|
||||
from enum import Enum
|
||||
from sqlalchemy import String, Boolean, Integer, ForeignKey, Enum as SAEnum, Text
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.core.db import Base
|
||||
|
||||
class RouterMethod(str, Enum):
|
||||
AUTO = "auto"
|
||||
REST = "rest"
|
||||
SSH = "ssh"
|
||||
API = "api"
|
||||
|
||||
class Router(Base):
|
||||
__tablename__ = "routers"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
name: Mapped[str] = mapped_column(String(200), unique=True, index=True)
|
||||
host: Mapped[str] = mapped_column(String(255))
|
||||
port_rest: Mapped[int] = mapped_column(Integer, default=443)
|
||||
port_ssh: Mapped[int] = mapped_column(Integer, default=22)
|
||||
port_api: Mapped[int] = mapped_column(Integer, default=8728)
|
||||
verify_ssl: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
preferred_method: Mapped[RouterMethod] = mapped_column(SAEnum(RouterMethod), default=RouterMethod.AUTO)
|
||||
tags: Mapped[str] = mapped_column(Text, default="")
|
||||
|
||||
class CredentialMethod(str, Enum):
|
||||
REST = "rest"
|
||||
SSH = "ssh"
|
||||
API = "api"
|
||||
|
||||
class RouterCredential(Base):
|
||||
__tablename__ = "router_credentials"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
router_id: Mapped[int] = mapped_column(ForeignKey("routers.id", ondelete="CASCADE"), index=True)
|
||||
method: Mapped[CredentialMethod] = mapped_column(SAEnum(CredentialMethod))
|
||||
username: Mapped[str] = mapped_column(String(255))
|
||||
secret_encrypted: Mapped[str] = mapped_column(Text)
|
||||
extra_json: Mapped[str] = mapped_column(Text, default="{}")
|
||||
|
||||
router = relationship("Router")
|
||||
18
backend/app/models/user.py
Normal file
18
backend/app/models/user.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from enum import Enum
|
||||
from sqlalchemy import String, Boolean, Enum as SAEnum
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.core.db import Base
|
||||
|
||||
class UserRole(str, Enum):
|
||||
ADMIN = "admin"
|
||||
USER = "user"
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = "users"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
email: Mapped[str] = mapped_column(String(255), unique=True, index=True)
|
||||
password_hash: Mapped[str] = mapped_column(String(255))
|
||||
role: Mapped[UserRole] = mapped_column(SAEnum(UserRole), default=UserRole.USER)
|
||||
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|
||||
Reference in New Issue
Block a user