-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(oonifindings): add postgresql support #862
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a589bfa
feat(oonifindings): add postgresql data models and migrations
DecFox ea3fca0
feat(oonifindings): replace clickhouse with postgresql (sqlalchemy)
DecFox 411951c
feat(oonifindings): replace service tests to use postgresql
DecFox 3cb9e73
fix: skip failing integration test
DecFox e0d52bb
Merge branch 'master' into issue/855
DecFox af0efde
refactor: changes to model from code review
DecFox 2289ced
refactor: change incident_id to finding_id in table
DecFox f4c97af
refactor: assemble multiple queries in single
DecFox 6814b7e
feat: add finding_slug column
DecFox 18c39bf
feat(oonifindings): add TODO for finding_slug
DecFox da401d5
fix: remove changes from oonirun database test
DecFox 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 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
53 changes: 53 additions & 0 deletions
53
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,53 @@ | ||
"""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( | ||
"incident_id", | ||
sa.String(), | ||
nullable=False, | ||
primary_key=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("CCs", sa.JSON(), nullable=True), | ||
sa.Column("ASNs", sa.JSON(), nullable=True), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Can we use consistent capitalization for these columns?
I would suggest There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done here: af0efde |
||
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,37 @@ | ||
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" | ||
|
||
# TODO(decfox): add primary key finding id | ||
incident_id: Mapped[str] = mapped_column(String, primary_key=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) | ||
|
||
CCs: 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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a column which is called something like finding_slug?
Also since we are now calling them findings, maybe this should be called
finding_id
or maybe even justid
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you elaborate a little more on what the
finding_slug
column represents? made thefinding_id
change here: 2289cedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically we would like to have the ability to have some kind of
slug
for each finding so that instead of it being this opaque number for examplehttps://explorer.ooni.org/findings/45013413801
it should be possible to configure it behttps://explorer.ooni.org/findings/2024-07-bangladesh-blocks-facebook
. This needs to be stored in the DB and we need to have the ability to lookup both by number (we can assume a number is the old format) and then to a permanent redirect to the new slug based format (which is nicer for humans and search engines).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for explaining this! I added a nullable
finding_slug
column for now: https://github.com/ooni/backend/pull/862/files#diff-ebc4627fea3725c4e6f1dafa16bfb842ed5cfdb74c8b292e203fc07cd2581ecbR30 along with aTODO
note in the models. We should be able to add the endpoint in the next version and also make this non-nullable (if required)