-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(oonifindings): add postgresql support (#862)
* feat(oonifindings): add postgresql data models and migrations * feat(oonifindings): replace clickhouse with postgresql (sqlalchemy) * feat(oonifindings): replace service tests to use postgresql * fix: skip failing integration test * refactor: changes to model from code review * refactor: change incident_id to finding_id in table * refactor: assemble multiple queries in single * feat: add finding_slug column * feat(oonifindings): add TODO for finding_slug * fix: remove changes from oonirun database test
- Loading branch information
Showing
15 changed files
with
537 additions
and
393 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
54 changes: 54 additions & 0 deletions
54
ooniapi/common/src/common/alembic/versions/a037e908f3a0_init_oonifindings.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,54 @@ | ||
"""init oonifindings | ||
Revision ID: a037e908f3a0 | ||
Revises: c9119c05cf42 | ||
Create Date: 2024-07-17 16:45:25.752551 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = 'a037e908f3a0' | ||
down_revision: Union[str, None] = "c9119c05cf42" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
op.create_table( | ||
"oonifinding", | ||
sa.Column( | ||
"finding_id", | ||
sa.String(), | ||
nullable=False, | ||
primary_key=True, | ||
), | ||
sa.Column("finding_slug", sa.String(), nullable=True), | ||
sa.Column("create_time", sa.DateTime(timezone=True), nullable=False), | ||
sa.Column("update_time", sa.DateTime(timezone=True), nullable=False), | ||
sa.Column("start_time", sa.DateTime(timezone=True), nullable=True), | ||
sa.Column("end_time", sa.DateTime(timezone=True), nullable=True), | ||
sa.Column("creator_account_id", sa.String(), nullable=False), | ||
sa.Column("title", sa.String(), nullable=False), | ||
sa.Column("short_description", sa.String(), nullable=False), | ||
sa.Column("text", sa.String(), nullable=False), | ||
sa.Column("reported_by", sa.String(), nullable=False), | ||
sa.Column("email_address", sa.String(), nullable=False), | ||
sa.Column("event_type", sa.String(), nullable=False), | ||
sa.Column("published", sa.Integer(), nullable=False), | ||
sa.Column("deleted", sa.Integer(), nullable=False, default=0), | ||
sa.Column("country_codes", sa.JSON(), nullable=True), | ||
sa.Column("asns", sa.JSON(), nullable=True), | ||
sa.Column("domains", sa.JSON(), nullable=True), | ||
sa.Column("tags", sa.JSON(), nullable=True), | ||
sa.Column("links", sa.JSON(), nullable=True), | ||
sa.Column("test_names", sa.JSON(), nullable=True), | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_table("oonifinding") |
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
28 changes: 0 additions & 28 deletions
28
ooniapi/services/oonifindings/migrations/clickhouse_init_tables.sql
This file was deleted.
Oops, something went wrong.
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
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,40 @@ | ||
from datetime import datetime | ||
from typing import List | ||
from sqlalchemy import String | ||
from sqlalchemy.orm import Mapped | ||
from sqlalchemy.orm import mapped_column | ||
|
||
from .common.models import UtcDateTime | ||
from .common.postgresql import Base | ||
|
||
|
||
class OONIFinding(Base): | ||
__tablename__ = "oonifinding" | ||
|
||
finding_id: Mapped[str] = mapped_column(String, primary_key=True) | ||
# TODO(decfox): this is nullable for now. We should | ||
# make this a non-nullable field eventually and have an endpoint | ||
# where we can query findings using the finding_slug. | ||
finding_slug: Mapped[str] = mapped_column(String, nullable=True) | ||
|
||
create_time: Mapped[datetime] = mapped_column(UtcDateTime()) | ||
update_time: Mapped[datetime] = mapped_column(UtcDateTime()) | ||
start_time: Mapped[datetime] = mapped_column(UtcDateTime(), nullable=True) | ||
end_time: Mapped[datetime] = mapped_column(UtcDateTime(), nullable=True) | ||
creator_account_id: Mapped[str] = mapped_column(String(32)) | ||
|
||
title: Mapped[str] = mapped_column() | ||
short_description: Mapped[str] = mapped_column() | ||
text: Mapped[str] = mapped_column() | ||
reported_by: Mapped[str] = mapped_column() | ||
email_address: Mapped[str] = mapped_column() | ||
event_type: Mapped[str] = mapped_column() | ||
published: Mapped[int] = mapped_column() | ||
deleted: Mapped[int] = mapped_column(default=0) | ||
|
||
country_codes: Mapped[List[str]] = mapped_column(nullable=True) | ||
asns: Mapped[List[str]] = mapped_column(nullable=True) | ||
domains: Mapped[List[str]] = mapped_column(nullable=True) | ||
tags: Mapped[List[str]] = mapped_column(nullable=True) | ||
links: Mapped[List[str]] = mapped_column(nullable=True) | ||
test_names: Mapped[List[str]] = mapped_column(nullable=True) |
Oops, something went wrong.