Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/expression constraint #1685

Merged
merged 2 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""Ensure search expression is not null

Revision ID: ceaf01079f4f
Revises: 3820a792d88a
Create Date: 2021-10-05 14:01:53.423667

"""
from alembic import op


# revision identifiers, used by Alembic.
revision = "ceaf01079f4f"
down_revision = "3820a792d88a"
branch_labels = None
depends_on = None


def upgrade():
op.execute("UPDATE search_filter SET expression = [] WHERE expression is null")
op.alter_column("search_filter", "expression", nullable=False)


def downgrade():
op.alter_column("search_filter", "expression", nullable=True)
4 changes: 2 additions & 2 deletions src/dispatch/search_filter/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SearchFilter(Base, ProjectMixin):
id = Column(Integer, primary_key=True)
name = Column(String)
description = Column(String)
expression = Column(JSON)
expression = Column(JSON, nullable=False)
creator_id = Column(Integer, ForeignKey(DispatchUser.id))
creator = relationship("DispatchUser", backref="search_filters")
type = Column(String)
Expand All @@ -34,7 +34,7 @@ class SearchFilter(Base, ProjectMixin):

# Pydantic models...
class SearchFilterBase(DispatchBase):
expression: Optional[List[dict]] = []
expression: List[dict]
name: NameStr
type: Optional[str]
description: Optional[str] = Field(None, nullable=True)
Expand Down