Skip to content
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
47 changes: 24 additions & 23 deletions ENV.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,30 @@ Note that some tasks/subtasks are themselves enabled by other tasks.

### Scheduled Task Flags

| Flag | Description |
|----------------------------------------|-------------------------------------------------------------------------------|
| `SCHEDULED_TASKS_FLAG` | All scheduled tasks. Disabling disables all other scheduled tasks. |
| `PUSH_TO_HUGGING_FACE_TASK_FLAG` | Pushes data to HuggingFace. |
| `POPULATE_BACKLOG_SNAPSHOT_TASK_FLAG` | Populates the backlog snapshot. |
| `DELETE_OLD_LOGS_TASK_FLAG` | Deletes old logs. |
| `RUN_URL_TASKS_TASK_FLAG` | Runs URL tasks. |
| `IA_PROBE_TASK_FLAG` | Extracts and links Internet Archives metadata to URLs. |
| `IA_SAVE_TASK_FLAG` | Saves URLs to Internet Archives. |
| `MARK_TASK_NEVER_COMPLETED_TASK_FLAG` | Marks tasks that were started but never completed (usually due to a restart). |
| `DELETE_STALE_SCREENSHOTS_TASK_FLAG` | Deletes stale screenshots for URLs already validated. |
| `TASK_CLEANUP_TASK_FLAG` | Cleans up tasks that are no longer needed. |
| `REFRESH_MATERIALIZED_VIEWS_TASK_FLAG` | Refreshes materialized views. |
| `UPDATE_URL_STATUS_TASK_FLAG` | Updates the status of URLs. |
| `DS_APP_SYNC_AGENCY_ADD_TASK_FLAG` | Adds new agencies to the Data Sources App|
| `DS_APP_SYNC_AGENCY_UPDATE_TASK_FLAG` | Updates existing agencies in the Data Sources App|
| `DS_APP_SYNC_AGENCY_DELETE_TASK_FLAG` | Deletes agencies in the Data Sources App|
| `DS_APP_SYNC_DATA_SOURCE_ADD_TASK_FLAG` | Adds new data sources to the Data Sources App|
| `DS_APP_SYNC_DATA_SOURCE_UPDATE_TASK_FLAG` | Updates existing data sources in the Data Sources App|
| `DS_APP_SYNC_DATA_SOURCE_DELETE_TASK_FLAG` | Deletes data sources in the Data Sources App|
| `DS_APP_SYNC_META_URL_ADD_TASK_FLAG` | Adds new meta URLs to the Data Sources App|
| `DS_APP_SYNC_META_URL_UPDATE_TASK_FLAG` | Updates existing meta URLs in the Data Sources App|
| `DS_APP_SYNC_META_URL_DELETE_TASK_FLAG` | Deletes meta URLs in the Data Sources App|
| Flag | Description |
|--------------------------------------------|-------------------------------------------------------------------------------|
| `SCHEDULED_TASKS_FLAG` | All scheduled tasks. Disabling disables all other scheduled tasks. |
| `PUSH_TO_HUGGING_FACE_TASK_FLAG` | Pushes data to HuggingFace. |
| `POPULATE_BACKLOG_SNAPSHOT_TASK_FLAG` | Populates the backlog snapshot. |
| `DELETE_OLD_LOGS_TASK_FLAG` | Deletes old logs. |
| `RUN_URL_TASKS_TASK_FLAG` | Runs URL tasks. |
| `IA_PROBE_TASK_FLAG` | Extracts and links Internet Archives metadata to URLs. |
| `IA_SAVE_TASK_FLAG` | Saves URLs to Internet Archives. |
| `MARK_TASK_NEVER_COMPLETED_TASK_FLAG` | Marks tasks that were started but never completed (usually due to a restart). |
| `DELETE_STALE_SCREENSHOTS_TASK_FLAG` | Deletes stale screenshots for URLs already validated. |
| `TASK_CLEANUP_TASK_FLAG` | Cleans up tasks that are no longer needed. |
| `REFRESH_MATERIALIZED_VIEWS_TASK_FLAG` | Refreshes materialized views. |
| `UPDATE_URL_STATUS_TASK_FLAG` | Updates the status of URLs. |
| `DS_APP_SYNC_AGENCY_ADD_TASK_FLAG` | Adds new agencies to the Data Sources App|
| `DS_APP_SYNC_AGENCY_UPDATE_TASK_FLAG` | Updates existing agencies in the Data Sources App|
| `DS_APP_SYNC_AGENCY_DELETE_TASK_FLAG` | Deletes agencies in the Data Sources App|
| `DS_APP_SYNC_DATA_SOURCE_ADD_TASK_FLAG` | Adds new data sources to the Data Sources App|
| `DS_APP_SYNC_DATA_SOURCE_UPDATE_TASK_FLAG` | Updates existing data sources in the Data Sources App|
| `DS_APP_SYNC_DATA_SOURCE_DELETE_TASK_FLAG` | Deletes data sources in the Data Sources App|
| `DS_APP_SYNC_META_URL_ADD_TASK_FLAG` | Adds new meta URLs to the Data Sources App|
| `DS_APP_SYNC_META_URL_UPDATE_TASK_FLAG` | Updates existing meta URLs in the Data Sources App|
| `DS_APP_SYNC_META_URL_DELETE_TASK_FLAG` | Deletes meta URLs in the Data Sources App|
| `INTEGRITY_MONITOR_TASK_FLAG` | Runs integrity checks. |

### URL Task Flags

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
"""Add integrity monitor

Revision ID: 5ac9d50b91c5
Revises: 1bb2dfad3275
Create Date: 2025-11-23 19:23:45.487445

"""
from typing import Sequence, Union

from alembic import op

from src.util.alembic_helpers import add_enum_value

# revision identifiers, used by Alembic.
revision: str = '5ac9d50b91c5'
down_revision: Union[str, None] = '1bb2dfad3275'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None

def upgrade() -> None:

Check warning on line 20 in alembic/versions/2025_11_23_1923-5ac9d50b91c5_add_integrity_monitor.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] alembic/versions/2025_11_23_1923-5ac9d50b91c5_add_integrity_monitor.py#L20 <103>

Missing docstring in public function
Raw output
./alembic/versions/2025_11_23_1923-5ac9d50b91c5_add_integrity_monitor.py:20:1: D103 Missing docstring in public function
_create_integrity_task()
_create_incomplete_data_sources_view()
_create_incomplete_meta_urls_view()
_create_url_both_data_source_and_meta_url_view()
_create_non_federal_agencies_no_location_view()

def _create_non_federal_agencies_no_location_view():
op.execute("""
create view integrity__non_federal_agencies_no_location_view as
select
ag.id as agency_id
from agencies ag
left join link_agencies__locations link on ag.id = link.agency_id
where ag.jurisdiction_type != 'federal'
and link.location_id is null
""")


def _create_url_both_data_source_and_meta_url_view():
op.execute("""
create view integrity__url_both_data_source_and_meta_url_view as
select
ds.url_id
from
ds_app_link_data_source ds
join ds_app_link_meta_url mu
on mu.url_id = ds.url_id
""")


def _create_incomplete_meta_urls_view():
op.execute("""
create view integrity__incomplete_meta_urls_view as
select
mu.url_id,
fuv.url_id is not null as has_validated_flag,
fuv.type as validated_type,
lau.url_id is not null as has_agency_flag
from ds_app_link_meta_url mu
left join flag_url_validated fuv on fuv.url_id = mu.url_id
left join link_agencies__urls lau on lau.url_id = mu.url_id
where
fuv.url_id is null
or fuv.type != 'meta url'
or lau.url_id is null
""")


def _create_incomplete_data_sources_view():
op.execute("""
create view integrity__incomplete_data_sources_view as
select
ds.url_id,
fuv.url_id is not null as has_validated_flag,
fuv.type as validated_type,
urt.url_id is not null as has_record_type,
lau.url_id is not null as has_agency_flag
from ds_app_link_data_source ds
left join flag_url_validated fuv on fuv.url_id = ds.url_id
left join url_record_type urt on urt.url_id = ds.url_id
left join link_agencies__urls lau on lau.url_id = ds.url_id
where
fuv.url_id is null
or fuv.type != 'data source'
or urt.url_id is null
or lau.url_id is null
""")


def _create_integrity_task():
add_enum_value(
enum_name="task_type",
enum_value="Integrity Monitor",
)

def downgrade() -> None:

Check warning on line 96 in alembic/versions/2025_11_23_1923-5ac9d50b91c5_add_integrity_monitor.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] alembic/versions/2025_11_23_1923-5ac9d50b91c5_add_integrity_monitor.py#L96 <103>

Missing docstring in public function
Raw output
./alembic/versions/2025_11_23_1923-5ac9d50b91c5_add_integrity_monitor.py:96:1: D103 Missing docstring in public function
pass
Empty file.
4 changes: 4 additions & 0 deletions src/core/tasks/scheduled/impl/integrity/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

Check warning on line 1 in src/core/tasks/scheduled/impl/integrity/exceptions.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/core/tasks/scheduled/impl/integrity/exceptions.py#L1 <100>

Missing docstring in public module
Raw output
./src/core/tasks/scheduled/impl/integrity/exceptions.py:1:1: D100 Missing docstring in public module

class IntegrityMonitorTaskException(Exception):

Check warning on line 3 in src/core/tasks/scheduled/impl/integrity/exceptions.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/core/tasks/scheduled/impl/integrity/exceptions.py#L3 <101>

Missing docstring in public class
Raw output
./src/core/tasks/scheduled/impl/integrity/exceptions.py:3:1: D101 Missing docstring in public class
pass

Check warning on line 4 in src/core/tasks/scheduled/impl/integrity/exceptions.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/core/tasks/scheduled/impl/integrity/exceptions.py#L4 <292>

no newline at end of file
Raw output
./src/core/tasks/scheduled/impl/integrity/exceptions.py:4:9: W292 no newline at end of file
30 changes: 30 additions & 0 deletions src/core/tasks/scheduled/impl/integrity/operator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from src.core.tasks.mixins.prereq import HasPrerequisitesMixin

Check warning on line 1 in src/core/tasks/scheduled/impl/integrity/operator.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/core/tasks/scheduled/impl/integrity/operator.py#L1 <100>

Missing docstring in public module
Raw output
./src/core/tasks/scheduled/impl/integrity/operator.py:1:1: D100 Missing docstring in public module
from src.core.tasks.scheduled.impl.integrity.exceptions import IntegrityMonitorTaskException
from src.core.tasks.scheduled.impl.integrity.queries.get import GetIntegrityTaskDataQueryBuilder
from src.core.tasks.scheduled.impl.integrity.queries.prereq import GetIntegrityTaskPrerequisitesQueryBuilder
from src.core.tasks.scheduled.templates.operator import ScheduledTaskOperatorBase
from src.db.enums import TaskType


class IntegrityMonitorTaskOperator(

Check warning on line 9 in src/core/tasks/scheduled/impl/integrity/operator.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/core/tasks/scheduled/impl/integrity/operator.py#L9 <101>

Missing docstring in public class
Raw output
./src/core/tasks/scheduled/impl/integrity/operator.py:9:1: D101 Missing docstring in public class
ScheduledTaskOperatorBase,
HasPrerequisitesMixin
):

@property
def task_type(self) -> TaskType:

Check warning on line 15 in src/core/tasks/scheduled/impl/integrity/operator.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/core/tasks/scheduled/impl/integrity/operator.py#L15 <102>

Missing docstring in public method
Raw output
./src/core/tasks/scheduled/impl/integrity/operator.py:15:1: D102 Missing docstring in public method
return TaskType.INTEGRITY_MONITOR

async def meets_task_prerequisites(self) -> bool:

Check warning on line 18 in src/core/tasks/scheduled/impl/integrity/operator.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/core/tasks/scheduled/impl/integrity/operator.py#L18 <102>

Missing docstring in public method
Raw output
./src/core/tasks/scheduled/impl/integrity/operator.py:18:1: D102 Missing docstring in public method
return await self.run_query_builder(
query_builder=GetIntegrityTaskPrerequisitesQueryBuilder()
)

async def inner_task_logic(self) -> None:

Check warning on line 23 in src/core/tasks/scheduled/impl/integrity/operator.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/core/tasks/scheduled/impl/integrity/operator.py#L23 <102>

Missing docstring in public method
Raw output
./src/core/tasks/scheduled/impl/integrity/operator.py:23:1: D102 Missing docstring in public method
failing_views: list[str] = await self.run_query_builder(
query_builder=GetIntegrityTaskDataQueryBuilder()
)
raise IntegrityMonitorTaskException(
f"Integrity Monitor Task failed for the following views {failing_views}",
)

Check warning on line 30 in src/core/tasks/scheduled/impl/integrity/operator.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/core/tasks/scheduled/impl/integrity/operator.py#L30 <391>

blank line at end of file
Raw output
./src/core/tasks/scheduled/impl/integrity/operator.py:30:1: W391 blank line at end of file
Empty file.
61 changes: 61 additions & 0 deletions src/core/tasks/scheduled/impl/integrity/queries/cte.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from sqlalchemy import select, literal, Exists, Label, or_

Check warning on line 1 in src/core/tasks/scheduled/impl/integrity/queries/cte.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/core/tasks/scheduled/impl/integrity/queries/cte.py#L1 <100>

Missing docstring in public module
Raw output
./src/core/tasks/scheduled/impl/integrity/queries/cte.py:1:1: D100 Missing docstring in public module

from src.db.models.templates_.base import Base
from src.db.models.views.integrity.incomplete_data_sources import IntegrityIncompleteDataSource
from src.db.models.views.integrity.incomplete_meta_urls import IntegrityIncompleteMetaURL
from src.db.models.views.integrity.non_federal_agencies_no_location import IntegrityNonFederalAgenciesNoLocation
from src.db.models.views.integrity.url_both_data_source_and_meta_url import IntegrityURLBothDataSourceAndMetaURL


def any_row_exists(

Check warning on line 10 in src/core/tasks/scheduled/impl/integrity/queries/cte.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/core/tasks/scheduled/impl/integrity/queries/cte.py#L10 <103>

Missing docstring in public function
Raw output
./src/core/tasks/scheduled/impl/integrity/queries/cte.py:10:1: D103 Missing docstring in public function
model: type[Base]
) -> Exists:
return (
select(
literal(1)
)
.select_from(
model
)
.exists()
)

class IntegrityTaskCTEContainer:

Check warning on line 23 in src/core/tasks/scheduled/impl/integrity/queries/cte.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/core/tasks/scheduled/impl/integrity/queries/cte.py#L23 <101>

Missing docstring in public class
Raw output
./src/core/tasks/scheduled/impl/integrity/queries/cte.py:23:1: D101 Missing docstring in public class

def __init__(

Check warning on line 25 in src/core/tasks/scheduled/impl/integrity/queries/cte.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/core/tasks/scheduled/impl/integrity/queries/cte.py#L25 <107>

Missing docstring in __init__
Raw output
./src/core/tasks/scheduled/impl/integrity/queries/cte.py:25:1: D107 Missing docstring in __init__
self,
):
self.models: list[type[Base]] = [
IntegrityURLBothDataSourceAndMetaURL,
IntegrityNonFederalAgenciesNoLocation,
IntegrityIncompleteMetaURL,
IntegrityIncompleteDataSource,
]

expressions: list[Label[bool]] = [
any_row_exists(model)
.label(model.__tablename__)
for model in self.models
]

self.cte = (
select(
*expressions
)
.cte(
name="integrity_task_cte",
)
)

@property
def any_rows_exist_query(self) -> select:

Check warning on line 51 in src/core/tasks/scheduled/impl/integrity/queries/cte.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/core/tasks/scheduled/impl/integrity/queries/cte.py#L51 <102>

Missing docstring in public method
Raw output
./src/core/tasks/scheduled/impl/integrity/queries/cte.py:51:1: D102 Missing docstring in public method
expression = [
getattr(self.cte.c, model.__tablename__)
for model in self.models
]
return select(or_(*expression))

@property
def select_all_columns_query(self) -> select:

Check warning on line 59 in src/core/tasks/scheduled/impl/integrity/queries/cte.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/core/tasks/scheduled/impl/integrity/queries/cte.py#L59 <102>

Missing docstring in public method
Raw output
./src/core/tasks/scheduled/impl/integrity/queries/cte.py:59:1: D102 Missing docstring in public method
return select(self.cte)

Check warning on line 61 in src/core/tasks/scheduled/impl/integrity/queries/cte.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/core/tasks/scheduled/impl/integrity/queries/cte.py#L61 <391>

blank line at end of file
Raw output
./src/core/tasks/scheduled/impl/integrity/queries/cte.py:61:1: W391 blank line at end of file
20 changes: 20 additions & 0 deletions src/core/tasks/scheduled/impl/integrity/queries/get.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from sqlalchemy import RowMapping

Check warning on line 1 in src/core/tasks/scheduled/impl/integrity/queries/get.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/core/tasks/scheduled/impl/integrity/queries/get.py#L1 <100>

Missing docstring in public module
Raw output
./src/core/tasks/scheduled/impl/integrity/queries/get.py:1:1: D100 Missing docstring in public module
from sqlalchemy.ext.asyncio import AsyncSession

from src.core.tasks.scheduled.impl.integrity.queries.cte import IntegrityTaskCTEContainer
from src.db.queries.base.builder import QueryBuilderBase


class GetIntegrityTaskDataQueryBuilder(QueryBuilderBase):

Check warning on line 8 in src/core/tasks/scheduled/impl/integrity/queries/get.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/core/tasks/scheduled/impl/integrity/queries/get.py#L8 <101>

Missing docstring in public class
Raw output
./src/core/tasks/scheduled/impl/integrity/queries/get.py:8:1: D101 Missing docstring in public class

async def run(self, session: AsyncSession) -> list[str]:

Check warning on line 10 in src/core/tasks/scheduled/impl/integrity/queries/get.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/core/tasks/scheduled/impl/integrity/queries/get.py#L10 <102>

Missing docstring in public method
Raw output
./src/core/tasks/scheduled/impl/integrity/queries/get.py:10:1: D102 Missing docstring in public method
cte = IntegrityTaskCTEContainer()
mapping: RowMapping = await self.sh.mapping(
session=session,
query=cte.select_all_columns_query
)
return [
model.__tablename__
for model in cte.models
if mapping[model.__tablename__]
]

Check warning on line 20 in src/core/tasks/scheduled/impl/integrity/queries/get.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/core/tasks/scheduled/impl/integrity/queries/get.py#L20 <292>

no newline at end of file
Raw output
./src/core/tasks/scheduled/impl/integrity/queries/get.py:20:10: W292 no newline at end of file
16 changes: 16 additions & 0 deletions src/core/tasks/scheduled/impl/integrity/queries/prereq.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from typing import Any

Check warning on line 1 in src/core/tasks/scheduled/impl/integrity/queries/prereq.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/core/tasks/scheduled/impl/integrity/queries/prereq.py#L1 <100>

Missing docstring in public module
Raw output
./src/core/tasks/scheduled/impl/integrity/queries/prereq.py:1:1: D100 Missing docstring in public module

from sqlalchemy.ext.asyncio import AsyncSession

from src.core.tasks.scheduled.impl.integrity.queries.cte import IntegrityTaskCTEContainer
from src.db.queries.base.builder import QueryBuilderBase


class GetIntegrityTaskPrerequisitesQueryBuilder(QueryBuilderBase):

Check warning on line 9 in src/core/tasks/scheduled/impl/integrity/queries/prereq.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/core/tasks/scheduled/impl/integrity/queries/prereq.py#L9 <101>

Missing docstring in public class
Raw output
./src/core/tasks/scheduled/impl/integrity/queries/prereq.py:9:1: D101 Missing docstring in public class

async def run(self, session: AsyncSession) -> Any:

Check warning on line 11 in src/core/tasks/scheduled/impl/integrity/queries/prereq.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/core/tasks/scheduled/impl/integrity/queries/prereq.py#L11 <102>

Missing docstring in public method
Raw output
./src/core/tasks/scheduled/impl/integrity/queries/prereq.py:11:1: D102 Missing docstring in public method
cte = IntegrityTaskCTEContainer()
return await self.sh.scalar(
session=session,
query=cte.any_rows_exist_query
)
8 changes: 8 additions & 0 deletions src/core/tasks/scheduled/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from src.core.tasks.scheduled.impl.delete_logs.operator import DeleteOldLogsTaskOperator
from src.core.tasks.scheduled.impl.delete_stale_screenshots.operator import DeleteStaleScreenshotsTaskOperator
from src.core.tasks.scheduled.impl.huggingface.operator import PushToHuggingFaceTaskOperator
from src.core.tasks.scheduled.impl.integrity.operator import IntegrityMonitorTaskOperator
from src.core.tasks.scheduled.impl.internet_archives.probe.operator import InternetArchivesProbeTaskOperator
from src.core.tasks.scheduled.impl.internet_archives.save.operator import InternetArchivesSaveTaskOperator
from src.core.tasks.scheduled.impl.mark_never_completed.operator import MarkTaskNeverCompletedOperator
Expand Down Expand Up @@ -127,6 +128,13 @@ async def load_entries(self) -> list[ScheduledTaskEntry]:
interval_minutes=IntervalEnum.DAILY.value,
enabled=self.setup_flag("REFRESH_MATERIALIZED_VIEWS_TASK_FLAG")
),
ScheduledTaskEntry(
operator=IntegrityMonitorTaskOperator(
adb_client=self.adb_client
),
interval_minutes=IntervalEnum.DAILY.value,
enabled=self.setup_flag("INTEGRITY_MONITOR_TASK_FLAG")
),
# Sync
## Adds
### Agency
Expand Down
1 change: 1 addition & 0 deletions src/db/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class TaskType(PyEnum):
TASK_CLEANUP = "Task Cleanup"
REFRESH_MATERIALIZED_VIEWS = "Refresh Materialized Views"
UPDATE_URL_STATUS = "Update URL Status"
INTEGRITY_MONITOR = "Integrity Monitor"

# Sync Tasks
SYNC_AGENCIES_ADD = "Sync Agencies Add"
Expand Down
3 changes: 3 additions & 0 deletions src/db/models/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ def location_id_column() -> Column[int]:

CURRENT_TIME_SERVER_DEFAULT = func.now()

VIEW_ARG = {"info": "view"}

def url_id_primary_key_constraint() -> PrimaryKeyConstraint:
return PrimaryKeyConstraint('url_id')


def county_column(nullable: bool = False) -> Column[int]:
return Column(
Integer(),
Expand Down
3 changes: 2 additions & 1 deletion src/db/models/impl/flag/url_validated/sqlalchemy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from sqlalchemy import PrimaryKeyConstraint
from sqlalchemy.orm import Mapped

from src.db.models.helpers import enum_column
from src.db.models.impl.flag.url_validated.enums import URLType
Expand All @@ -19,7 +20,7 @@ class FlagURLValidated(
),
)

type = enum_column(
type: Mapped[URLType] = enum_column(
enum_type=URLType,
name="url_type",
)
9 changes: 8 additions & 1 deletion src/db/models/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from sqlalchemy import Column, Integer, ForeignKey, TIMESTAMP, event

from src.db.models.exceptions import WriteToViewError
from src.db.models.helpers import get_created_at_column, CURRENT_TIME_SERVER_DEFAULT
from src.db.models.helpers import get_created_at_column, CURRENT_TIME_SERVER_DEFAULT, url_id_primary_key_constraint, \
VIEW_ARG


class URLDependentMixin:
Expand Down Expand Up @@ -90,3 +91,9 @@
@staticmethod
def _block_write(mapper, connection, target):
raise WriteToViewError(f"{type(target).__name__} is a read-only view.")

class URLDependentViewMixin(URLDependentMixin, ViewMixin):

Check warning on line 95 in src/db/models/mixins.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/db/models/mixins.py#L95 <101>

Missing docstring in public class
Raw output
./src/db/models/mixins.py:95:1: D101 Missing docstring in public class
__table_args__ = (
url_id_primary_key_constraint(),
VIEW_ARG
)

Check warning on line 99 in src/db/models/mixins.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] src/db/models/mixins.py#L99 <292>

no newline at end of file
Raw output
./src/db/models/mixins.py:99:6: W292 no newline at end of file
3 changes: 2 additions & 1 deletion src/db/models/views/dependent_locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"""
from sqlalchemy import Column, Integer, ForeignKey

from src.db.models.helpers import VIEW_ARG
from src.db.models.mixins import ViewMixin
from src.db.models.templates_.base import Base

Expand All @@ -39,7 +40,7 @@ class DependentLocationView(Base, ViewMixin):

__tablename__ = "dependent_locations"
__table_args__ = (
{"info": "view"}
VIEW_ARG,
)

parent_location_id = Column(
Expand Down
Empty file.
Loading