This repository was archived by the owner on Sep 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 629
add base concept of entities to signals #2977
Merged
Merged
Changes from 10 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b015458
add base concenpt of entities to signals
wssheldon 26091af
Add entity model to store type results and add entity case tab
wssheldon 736986a
Add missing import and remove unused import
wssheldon 69665c7
Merge branch 'master' into enhancement/entities
wssheldon c620424
Remove debug statements and sleep from find_entities function
wssheldon 1d7fc23
Fix entity_type update service and fix signal instance popover in table
wssheldon 92abd02
fix service tests, signal_instance id should be uuid not integer
wssheldon a50d6ab
Merge branch 'master' into enhancement/entities
wssheldon b8a728f
Remove debug console.log statement
wssheldon 547feeb
move find_entities function to entity service
wssheldon 7f7d34b
Update comment
wssheldon f67f057
Merge branch 'master' into enhancement/entities
wssheldon 4ac9a45
Remove global find from front-end, add regex help message about groups
wssheldon c875a8a
Address @kglisson comments
wssheldon d19d9e3
Merge branch 'master' into enhancement/entities
wssheldon 342be5f
Make case edit sheet wider to give tabs some room to breathe
wssheldon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,73 @@ | ||
| 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 ( | ||
| EntityTypeRead, | ||
| EntityTypeCreate, | ||
| 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", 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[EntityTypeRead] | ||
wssheldon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| class EntityPagination(DispatchBase): | ||
| items: List[EntityRead] | ||
| total: int | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.