-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add base concept of entities to signals (#2977)
* add base concenpt of entities to signals * Add entity model to store type results and add entity case tab * Add missing import and remove unused import * Remove debug statements and sleep from find_entities function * Fix entity_type update service and fix signal instance popover in table * fix service tests, signal_instance id should be uuid not integer * Remove debug console.log statement * move find_entities function to entity service * Update comment * Remove global find from front-end, add regex help message about groups * Address @kglisson comments * Make case edit sheet wider to give tabs some room to breathe
- Loading branch information
Showing
34 changed files
with
2,233 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
src/dispatch/database/revisions/tenant/versions/2023-02-09_8746b4e292d2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
"""Adds entity and entity type tables and associations | ||
Revision ID: 8746b4e292d2 | ||
Revises: 941efd922446 | ||
Create Date: 2023-02-09 23:18:11.326027 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects.postgresql import TSVECTOR, UUID | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "8746b4e292d2" | ||
down_revision = "941efd922446" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! | ||
|
||
# EntityType | ||
op.create_table( | ||
"entity_type", | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column("name", sa.String(), nullable=True), | ||
sa.Column("description", sa.String(), nullable=True), | ||
sa.Column("field", sa.String(), nullable=True), | ||
sa.Column("regular_expression", sa.String(), nullable=True), | ||
sa.Column("global_find", sa.Boolean(), nullable=True), | ||
sa.Column("enabled", sa.Boolean(), nullable=True), | ||
sa.Column("search_vector", TSVECTOR, nullable=True), | ||
sa.Column("project_id", sa.Integer(), nullable=True), | ||
sa.Column("updated_at", sa.DateTime(), nullable=True), | ||
sa.Column("created_at", sa.DateTime(), nullable=True), | ||
sa.ForeignKeyConstraint(["project_id"], ["project.id"], ondelete="CASCADE"), | ||
sa.PrimaryKeyConstraint("id"), | ||
sa.UniqueConstraint("name", "project_id"), | ||
) | ||
op.create_table( | ||
"assoc_signal_entity_types", | ||
sa.Column("signal_id", sa.Integer(), nullable=False), | ||
sa.Column("entity_type_id", sa.Integer(), nullable=False), | ||
sa.ForeignKeyConstraint(["signal_id"], ["signal.id"], ondelete="CASCADE"), | ||
sa.ForeignKeyConstraint(["entity_type_id"], ["entity_type.id"], ondelete="CASCADE"), | ||
sa.PrimaryKeyConstraint("signal_id", "entity_type_id"), | ||
) | ||
op.create_index( | ||
"entity_type_search_vector_idx", | ||
"entity_type", | ||
["search_vector"], | ||
unique=False, | ||
postgresql_using="gin", | ||
) | ||
|
||
# Entity | ||
op.create_table( | ||
"entity", | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column("name", sa.String(), nullable=True), | ||
sa.Column("description", sa.String(), nullable=True), | ||
sa.Column("value", sa.String(), nullable=True), | ||
sa.Column("source", sa.Boolean(), nullable=True), | ||
sa.Column("entity_type_id", sa.Integer(), nullable=False), | ||
sa.Column("search_vector", TSVECTOR, nullable=True), | ||
sa.Column("project_id", sa.Integer(), nullable=True), | ||
sa.Column("updated_at", sa.DateTime(), nullable=True), | ||
sa.Column("created_at", sa.DateTime(), nullable=True), | ||
sa.ForeignKeyConstraint( | ||
["entity_type_id"], | ||
["entity_type.id"], | ||
), | ||
sa.ForeignKeyConstraint(["project_id"], ["project.id"], ondelete="CASCADE"), | ||
sa.PrimaryKeyConstraint("id"), | ||
sa.UniqueConstraint("name", "project_id"), | ||
) | ||
op.create_index( | ||
"ix_entity_search_vector", | ||
"entity", | ||
["search_vector"], | ||
unique=False, | ||
postgresql_using="gin", | ||
) | ||
op.create_table( | ||
"assoc_signal_instance_entities", | ||
sa.Column("signal_instance_id", UUID(), nullable=False), | ||
sa.Column("entity_id", sa.Integer(), nullable=False), | ||
sa.ForeignKeyConstraint(["signal_instance_id"], ["signal_instance.id"], ondelete="CASCADE"), | ||
sa.ForeignKeyConstraint(["entity_id"], ["entity.id"], ondelete="CASCADE"), | ||
sa.PrimaryKeyConstraint("signal_instance_id", "entity_id"), | ||
) | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_index("ix_entity_search_vector", table_name="entity") | ||
op.drop_table("entity") | ||
op.drop_table("entity_type") | ||
op.drop_index("entity_type_search_vector_idx", table_name="entity", postgresql_using="gin") | ||
op.drop_table("assoc_signal_entity_types") | ||
op.drop_table("assoc_signal_instance_entity_types") | ||
# ### end Alembic commands ### |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
from typing import Optional, List | ||
from pydantic import Field | ||
|
||
from sqlalchemy import Column, Integer, String, ForeignKey | ||
from sqlalchemy.orm import relationship | ||
from sqlalchemy.sql.schema import UniqueConstraint | ||
from sqlalchemy_utils import TSVectorType | ||
|
||
from dispatch.database.core import Base | ||
from dispatch.models import DispatchBase, TimeStampMixin, ProjectMixin, PrimaryKey | ||
from dispatch.project.models import ProjectRead | ||
from dispatch.entity_type.models import ( | ||
EntityTypeCreate, | ||
EntityTypeRead, | ||
EntityTypeReadMinimal, | ||
EntityTypeUpdate, | ||
) | ||
|
||
|
||
class Entity(Base, TimeStampMixin, ProjectMixin): | ||
__table_args__ = (UniqueConstraint("name", "project_id"),) | ||
|
||
# Columns | ||
id = Column(Integer, primary_key=True) | ||
name = Column(String) | ||
description = Column(String) | ||
value = Column(String) | ||
source = Column(String) | ||
|
||
# Relationships | ||
entity_type_id = Column(Integer, ForeignKey("entity_type.id"), nullable=False) | ||
entity_type = relationship("EntityType", backref="entity") | ||
|
||
# the catalog here is simple to help matching "named entities" | ||
search_vector = Column( | ||
TSVectorType( | ||
"name", | ||
"description", | ||
weights={"name": "A", "description": "B"}, | ||
regconfig="pg_catalog.simple", | ||
) | ||
) | ||
|
||
|
||
# Pydantic models | ||
class EntityBase(DispatchBase): | ||
name: Optional[str] = Field(None, nullable=True) | ||
source: Optional[str] = Field(None, nullable=True) | ||
value: Optional[str] = Field(None, nullable=True) | ||
description: Optional[str] = Field(None, nullable=True) | ||
|
||
|
||
class EntityCreate(EntityBase): | ||
id: Optional[PrimaryKey] | ||
entity_type: EntityTypeCreate | ||
project: ProjectRead | ||
|
||
|
||
class EntityUpdate(EntityBase): | ||
id: Optional[PrimaryKey] | ||
entity_type: Optional[EntityTypeUpdate] | ||
|
||
|
||
class EntityRead(EntityBase): | ||
id: PrimaryKey | ||
entity_type: Optional[EntityTypeRead] | ||
project: ProjectRead | ||
|
||
|
||
class EntityReadMinimal(DispatchBase): | ||
id: PrimaryKey | ||
name: Optional[str] = Field(None, nullable=True) | ||
source: Optional[str] = Field(None, nullable=True) | ||
value: Optional[str] = Field(None, nullable=True) | ||
description: Optional[str] = Field(None, nullable=True) | ||
entity_type: Optional[EntityTypeReadMinimal] | ||
|
||
|
||
class EntityPagination(DispatchBase): | ||
items: List[EntityRead] | ||
total: int |
Oops, something went wrong.