Skip to content

Commit d07eee7

Browse files
HJ-92: add table for storing monitor execution records (#5704)
1 parent 29f3415 commit d07eee7

File tree

4 files changed

+125
-12
lines changed

4 files changed

+125
-12
lines changed

.fides/db_dataset.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,25 @@ dataset:
916916
data_categories: [system.operations]
917917
- name: updated_at
918918
data_categories: [system.operations]
919+
- name: monitorexecution
920+
data_categories: []
921+
fields:
922+
- name: id
923+
data_categories: [system.operations]
924+
- name: monitor_config_key
925+
data_categories: [system.operations]
926+
- name: status
927+
data_categories: [system.operations]
928+
- name: started
929+
data_categories: [system.operations]
930+
- name: completed
931+
data_categories: [system.operations]
932+
- name: classification_instances
933+
data_categories: [system.operations]
934+
- name: created_at
935+
data_categories: [system.operations]
936+
- name: updated_at
937+
data_categories: [system.operations]
919938
- name: policy
920939
data_categories: []
921940
fields:

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ Changes can also be flagged with a GitHub label for tracking purposes. The URL o
4747
### Developer Experience
4848
- Migrated radio buttons and groups to Ant Design [#5681](https://github.com/ethyca/fides/pull/5681)
4949

50+
### Added
51+
- Migration to add the `data_uses` column to `stagedresource` table, prereqs for Data Catalog work in Fidesplus [#5600](https://github.com/ethyca/fides/pull/5600/) https://github.com/ethyca/fides/labels/db-migration
52+
- Migration to add the `monitorexecution` table used by fidesplus to persist `MonitorExecution` records to DB [#5704](https://github.com/ethyca/fides/pull/5704) https://github.com/ethyca/fides/labels/db-migration
53+
5054
### Fixed
5155
- Updating mongodb connectors so it can support usernames and password with URL encoded characters [#5682](https://github.com/ethyca/fides/pull/5682)
5256
- After creating a new system, the url is now updated correctly to the new system edit page [#5701](https://github.com/ethyca/fides/pull/5701)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"""create table for persisting MonitorExecution records
2+
3+
Revision ID: ed96417b07d8
4+
Revises: 1088e8353890
5+
Create Date: 2025-01-27 23:41:59.803285
6+
7+
"""
8+
9+
import sqlalchemy as sa
10+
from alembic import op
11+
from sqlalchemy.dialects import postgresql
12+
13+
# revision identifiers, used by Alembic.
14+
revision = "ed96417b07d8"
15+
down_revision = "1088e8353890"
16+
branch_labels = None
17+
depends_on = None
18+
19+
20+
def upgrade():
21+
op.create_table(
22+
"monitorexecution",
23+
sa.Column("id", sa.String(), primary_key=True),
24+
sa.Column("monitor_config_key", sa.String(), nullable=False),
25+
sa.Column("status", sa.String(), nullable=True),
26+
sa.Column("started", sa.DateTime(), nullable=True, default=sa.func.now()),
27+
sa.Column("completed", sa.DateTime(), nullable=True),
28+
sa.Column(
29+
"classification_instances",
30+
postgresql.ARRAY(sa.String()),
31+
nullable=False,
32+
default=[],
33+
),
34+
sa.Column(
35+
"created_at",
36+
sa.DateTime(timezone=True),
37+
server_default=sa.text("now()"),
38+
nullable=True,
39+
),
40+
sa.Column(
41+
"updated_at",
42+
sa.DateTime(timezone=True),
43+
server_default=sa.text("now()"),
44+
nullable=True,
45+
),
46+
sa.PrimaryKeyConstraint("id"),
47+
)
48+
op.create_index(
49+
"ix_monitorexecution_monitor_config_key",
50+
"monitorexecution",
51+
["monitor_config_key"],
52+
)
53+
54+
55+
def downgrade():
56+
op.drop_table("monitorexecution")
57+
op.drop_index(
58+
"ix_monitorexecution_monitor_config_key", table_name="monitorexecution"
59+
)

src/fides/api/models/detection_discovery.py

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from __future__ import annotations
22

3-
from datetime import datetime
3+
from datetime import datetime, timezone
44
from enum import Enum
55
from typing import Any, Dict, Iterable, List, Optional, Type
66

77
from loguru import logger
8-
from sqlalchemy import ARRAY, Boolean, Column, DateTime, ForeignKey, String
8+
from sqlalchemy import ARRAY, Boolean, Column, DateTime, ForeignKey, String, func
99
from sqlalchemy.dialects.postgresql import JSONB
1010
from sqlalchemy.ext.asyncio import AsyncSession
1111
from sqlalchemy.ext.mutable import MutableDict
@@ -16,16 +16,6 @@
1616
from fides.api.db.base_class import Base, FidesBase
1717
from fides.api.models.connectionconfig import ConnectionConfig
1818

19-
# class MonitorExecution(BaseModel):
20-
# id: str
21-
# monitor_config_id: str
22-
# status: Optional[str]
23-
# started: Optional[datetime]
24-
# completed: Optional[datetime]
25-
# classification_instances: List[str] = PydanticField(
26-
# default_factory=list
27-
# ) # TODO: formalize to FK
28-
2919

3020
class DiffStatus(Enum):
3121
ADDITION = "addition"
@@ -118,6 +108,12 @@ class MonitorConfig(Base):
118108

119109
connection_config = relationship(ConnectionConfig)
120110

111+
executions = relationship(
112+
"MonitorExecution",
113+
cascade="all, delete-orphan",
114+
backref="monitor_config",
115+
)
116+
121117
@property
122118
def connection_config_key(self) -> str:
123119
"""Derives the `connection_config_key`"""
@@ -348,6 +344,41 @@ def mark_as_addition(
348344
parent_resource.add_child_diff_status(DiffStatus.ADDITION)
349345

350346

347+
class MonitorExecution(Base):
348+
"""
349+
Monitor execution record used for data detection and discovery.
350+
351+
Each monitor execution references `MonitorConfig`, which provide it with underlying
352+
configuration details used in connecting to the external data store.
353+
"""
354+
355+
id = Column(String, primary_key=True)
356+
monitor_config_key = Column(
357+
String,
358+
ForeignKey(MonitorConfig.key),
359+
nullable=False,
360+
index=True,
361+
)
362+
status = Column(String, nullable=True)
363+
started = Column(
364+
DateTime(timezone=True), nullable=True, default=datetime.now(timezone.utc)
365+
)
366+
completed = Column(DateTime(timezone=True), nullable=True)
367+
classification_instances = Column(
368+
ARRAY(String),
369+
index=False,
370+
unique=False,
371+
nullable=False,
372+
default=list,
373+
)
374+
created_at = Column(DateTime(timezone=True), server_default=func.now())
375+
updated_at = Column(
376+
DateTime(timezone=True),
377+
server_default=func.now(),
378+
onupdate=func.now(),
379+
)
380+
381+
351382
def fetch_staged_resources_by_type_query(
352383
resource_type: str,
353384
monitor_config_ids: Optional[List[str]] = None,

0 commit comments

Comments
 (0)