-
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.
Features: * Add support for filtering by theme, domains, country_codes and asns * Add support for setting slug of finding * Add support for retrieving findings by slug Changed: * It's now possible to create a finding with the published flag set on creation Fixes: * Fix bug in end_time not being returned * Fix creation to behave like old explorer Closes: * api: findings add support for storing and filtering by theme #889 * api: add support for filtering by domain name in findings endpoints #881
- Loading branch information
Showing
6 changed files
with
314 additions
and
122 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
ooniapi/common/src/common/alembic/versions/8e7ecea5c2f5_themes_column.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,63 @@ | ||
"""themes column | ||
Revision ID: 8e7ecea5c2f5 | ||
Revises: a037e908f3a0 | ||
Create Date: 2024-10-11 12:03:07.662702 | ||
""" | ||
|
||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "8e7ecea5c2f5" | ||
down_revision: Union[str, None] = "a037e908f3a0" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def convert_json_to_array(column_name: str): | ||
op.add_column("oonifinding", sa.Column(f"{column_name}_tmp", sa.ARRAY(sa.String))) | ||
op.execute( | ||
f""" | ||
UPDATE oonifinding | ||
SET {column_name}_tmp = ARRAY(SELECT json_array_elements_text({column_name})) | ||
""" | ||
) | ||
op.drop_column("oonifinding", column_name) | ||
op.alter_column("oonifinding", f"{column_name}_tmp", new_column_name=column_name) | ||
|
||
|
||
def convert_array_to_json(column_name: str): | ||
op.add_column("oonifinding", sa.Column(f"{column_name}_tmp", sa.JSON())) | ||
op.execute( | ||
f""" | ||
UPDATE oonifinding | ||
SET {column_name}_tmp = to_json({column_name}) | ||
""" | ||
) | ||
op.drop_column("oonifinding", column_name) | ||
op.alter_column("oonifinding", f"{column_name}_tmp", new_column_name=column_name) | ||
|
||
|
||
def upgrade() -> None: | ||
op.add_column("oonifinding", sa.Column("themes", sa.ARRAY(sa.String()))) | ||
convert_json_to_array("country_codes") | ||
convert_json_to_array("asns") | ||
convert_json_to_array("domains") | ||
convert_json_to_array("tags") | ||
convert_json_to_array("links") | ||
convert_json_to_array("test_names") | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_column("oonifinding", "themes") | ||
convert_array_to_json("country_codes") | ||
convert_array_to_json("asns") | ||
convert_array_to_json("domains") | ||
convert_array_to_json("tags") | ||
convert_array_to_json("links") | ||
convert_array_to_json("test_names") |
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
Oops, something went wrong.