Skip to content

Commit

Permalink
Adding project_id column to Feedback table
Browse files Browse the repository at this point in the history
  • Loading branch information
whitdog47 committed Oct 18, 2024
1 parent cfa072b commit 0d4fe49
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Adds case_id to feedback
"""Adds case_id and project_id to feedback
Revision ID: 3c49f62d7914
Revises: b8c1a8a4d957
Expand All @@ -8,6 +8,8 @@

from alembic import op
import sqlalchemy as sa
from sqlalchemy.orm import Session
from dispatch.feedback.incident.models import Feedback

# revision identifiers, used by Alembic.
revision = "3c49f62d7914"
Expand All @@ -19,12 +21,43 @@
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("feedback", sa.Column("case_id", sa.Integer(), nullable=True))
op.create_foreign_key(None, "feedback", "case", ["case_id"], ["id"], ondelete="CASCADE")
op.create_foreign_key(
"assoc_feedback_case_id_fkey",
"feedback",
"case",
["case_id"],
["id"],
ondelete="CASCADE",
)
op.add_column("feedback", sa.Column("project_id", sa.Integer(), nullable=True))
op.create_foreign_key(
"assoc_feedback_project_id_fkey",
"feedback",
"project",
["project_id"],
["id"],
ondelete="CASCADE",
)

bind = op.get_bind()
session = Session(bind=bind)

instances = session.query(Feedback).all()

for instance in instances:
if instance.incident:
instance.project_id = instance.incident.project_id
elif instance.case:
instance.project_id = instance.case.project_id

session.commit()
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, "feedback", type_="foreignkey")
op.drop_constraint("assoc_feedback_case_id_fkey", "feedback", type_="foreignkey")
op.drop_column("feedback", "case_id")
op.drop_constraint("assoc_feedback_project_id_fkey", "feedback", type_="foreignkey")
op.drop_column("feedback", "project_id")
# ### end Alembic commands ###
7 changes: 3 additions & 4 deletions src/dispatch/database/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,8 @@ def build_filters(filter_spec):

if not _is_iterable_filter(fn_args):
raise BadFilterFormat(
"`{}` value must be an iterable across the function " "arguments".format(
boolean_function.key
)
"`{}` value must be an iterable across the function "
"arguments".format(boolean_function.key)
)
if boolean_function.only_one_arg and len(fn_args) != 1:
raise BadFilterFormat(
Expand Down Expand Up @@ -347,8 +346,8 @@ def apply_filter_specific_joins(model: Base, filter_spec: dict, query: orm.query
# this is required because by default sqlalchemy-filter's auto-join
# knows nothing about how to join many-many relationships.
model_map = {
(Feedback, "Project"): (Incident, False),
(Feedback, "Incident"): (Incident, False),
(Feedback, "Case"): (Case, False),
(Task, "Project"): (Incident, False),
(Task, "Incident"): (Incident, False),
(Task, "IncidentPriority"): (Incident, False),
Expand Down
15 changes: 9 additions & 6 deletions src/dispatch/feedback/incident/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@

from dispatch.database.core import Base
from dispatch.incident.models import IncidentReadMinimal
from dispatch.models import DispatchBase, TimeStampMixin, FeedbackMixin, PrimaryKey, Pagination
from dispatch.models import (
DispatchBase,
TimeStampMixin,
FeedbackMixin,
PrimaryKey,
Pagination,
ProjectMixin,
)
from dispatch.participant.models import ParticipantRead
from dispatch.project.models import ProjectRead
from dispatch.case.models import CaseReadMinimal

from .enums import FeedbackRating


class Feedback(TimeStampMixin, FeedbackMixin, Base):
class Feedback(TimeStampMixin, FeedbackMixin, ProjectMixin, Base):
# Columns
id = Column(Integer, primary_key=True)

Expand All @@ -33,10 +40,6 @@ class Feedback(TimeStampMixin, FeedbackMixin, Base):
)
)

@hybrid_property
def project(self):
return self.incident.project if self.incident else self.case.project


# Pydantic models
class FeedbackBase(DispatchBase):
Expand Down
2 changes: 2 additions & 0 deletions src/dispatch/static/dispatch/src/feedback/incident/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export default {
"table.options.descending",
"table.options.filters",
"table.options.filters.incident",
"table.options.filters.case",
"table.options.filters.rating",
"table.options.filters.feedback",
"table.options.filters.participant",
Expand Down Expand Up @@ -179,6 +180,7 @@ export default {
vm.sortBy,
vm.descending,
vm.incident,
vm.case,
vm.rating,
vm.feedback,
vm.project,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const getDefaultSelectedState = () => {
feedback: null,
id: null,
incident: null,
case: null,
participant: null,
project: null,
rating: null,
Expand Down

0 comments on commit 0d4fe49

Please sign in to comment.