aboutsummaryrefslogtreecommitdiffstats
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rw-r--r--backend/models/orm/__init__.py30
-rw-r--r--backend/models/orm/admins.py14
-rw-r--r--backend/models/orm/forms.py61
3 files changed, 105 insertions, 0 deletions
diff --git a/backend/models/orm/__init__.py b/backend/models/orm/__init__.py
index 4c8a6b4..4db39ae 100644
--- a/backend/models/orm/__init__.py
+++ b/backend/models/orm/__init__.py
@@ -1,7 +1,37 @@
"""Database models."""
+from .admins import Admin
from .base import Base
+from .forms import Form, FormEditor, FormFeatures
+from .questions import (
+ FormCheckboxQuestion,
+ FormCodeQuestion,
+ FormCodeQuestionTest,
+ FormQuestion,
+ FormRadioQuestion,
+ FormRangeQuestion,
+ FormSectionQuestion,
+ FormSelectQuestion,
+ FormTextQuestion,
+ FormTimezoneQuestion,
+ FormVoteQuestion,
+)
__all__ = (
+ "Admin",
"Base",
+ "Form",
+ "FormCheckboxQuestion",
+ "FormCodeQuestion",
+ "FormCodeQuestionTest",
+ "FormEditor",
+ "FormFeatures",
+ "FormQuestion",
+ "FormRadioQuestion",
+ "FormRangeQuestion",
+ "FormSectionQuestion",
+ "FormSelectQuestion",
+ "FormTextQuestion",
+ "FormTimezoneQuestion",
+ "FormVoteQuestion",
)
diff --git a/backend/models/orm/admins.py b/backend/models/orm/admins.py
new file mode 100644
index 0000000..7eee008
--- /dev/null
+++ b/backend/models/orm/admins.py
@@ -0,0 +1,14 @@
+"""Discord members who have admin access."""
+
+from sqlalchemy.orm import Mapped, mapped_column
+from sqlalchemy.types import BigInteger
+
+from .base import Base
+
+
+class Admin(Base):
+ """A discord user_id that has admin level access to forms."""
+
+ __tablename__ = "admins"
+
+ user_id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
diff --git a/backend/models/orm/forms.py b/backend/models/orm/forms.py
new file mode 100644
index 0000000..489b71b
--- /dev/null
+++ b/backend/models/orm/forms.py
@@ -0,0 +1,61 @@
+"""All forms that can have submissions."""
+
+import sqlalchemy.dialects.postgresql as pg
+from sqlalchemy import ForeignKey
+from sqlalchemy.orm import Mapped, mapped_column, relationship
+from sqlalchemy.types import BigInteger, Enum, Text
+
+from backend.constants import FormFeatures
+
+from .base import Base
+
+
+class Form(Base):
+ """A form that users can submit responses to."""
+
+ __tablename__ = "forms"
+
+ form_id: Mapped[int] = mapped_column(primary_key=True)
+
+ short_name: Mapped[str] = mapped_column(Text, nullable=False, index=True)
+ name: Mapped[str] = mapped_column(Text, nullable=False)
+ description: Mapped[str] = mapped_column(Text, nullable=False)
+ submission_text: Mapped[str | None] = mapped_column(Text, nullable=True)
+
+ webhook_url: Mapped[str | None] = mapped_column(Text, nullable=True)
+ webhook_message: Mapped[str | None] = mapped_column(Text, nullable=True)
+
+ discord_role: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
+
+ features: Mapped[list[FormFeatures]] = mapped_column(pg.ARRAY(Enum(FormFeatures), dimensions=1))
+
+ form_response_readers: Mapped[list["FormResponseReader"]] = relationship(
+ cascade="all, delete",
+ passive_deletes=True,
+ )
+ form_editors: Mapped[list["FormEditor"]] = relationship(
+ cascade="all, delete",
+ passive_deletes=True,
+ )
+
+
+class FormResponseReader(Base):
+ """A Discord user that can read a given form."""
+
+ __tablename__ = "form_response_readers"
+
+ form_id: Mapped[int] = mapped_column(
+ ForeignKey("forms.form_id", ondelete="CASCADE"), primary_key=True
+ )
+ user_id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
+
+
+class FormEditor(Base):
+ """A Discord user that can edit a given form."""
+
+ __tablename__ = "form_editors"
+
+ form_id: Mapped[int] = mapped_column(
+ ForeignKey("forms.form_id", ondelete="CASCADE"), primary_key=True
+ )
+ user_id: Mapped[int] = mapped_column(BigInteger, primary_key=True)