From 7cc043b42a9ccb3d774b37e36b823d8db6e04ebb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arturo=20Filast=C3=B2?= Date: Wed, 13 Mar 2024 17:08:58 +0100 Subject: [PATCH] OONI Run v2 DB Migration (#819) Add support for running db migration in docker image. We should not have a separate process for doing the migration, but it should be runnable from directly inside of the docker image of the installed software component. * Remove dbmigration codebuild task. We should run them inside of the container repl * Move almebic script to top level directory * Fix docker build * Fix hatch version getting * Fix db migration * Fix path to alembic migrations * Add coverage to gitignore --- ooniapi/services/oonirun/.dockerignore | 10 + ooniapi/services/oonirun/.gitignore | 1 + ooniapi/services/oonirun/Dockerfile | 12 +- ooniapi/services/oonirun/Makefile | 3 +- ooniapi/services/oonirun/README.md | 15 + .../{src/oonirun => }/alembic/__init__.py | 0 .../oonirun/{src/oonirun => }/alembic/env.py | 0 .../versions/981d92cf8790_init_tables.py | 0 .../oonirun/buildspec-dbmigration.yml | 26 -- ooniapi/services/oonirun/pyproject.toml | 5 +- .../oonirun/src/oonirun/alembic/Readme.md | 15 - ...841cb9549_make_oonirun_link_id_a_string.py | 37 --- ...add_expiration_date_color_columns_drop_.py | 32 --- .../9973a7e1f96c_oonirun_nettest_table.py | 256 ------------------ .../f96cf47f2791_create_oonirun_db.py | 44 --- .../src/oonirun/alembic/script.py.mako | 26 -- ooniapi/services/oonirun/tests/conftest.py | 4 +- 17 files changed, 40 insertions(+), 446 deletions(-) create mode 100644 ooniapi/services/oonirun/.dockerignore rename ooniapi/services/oonirun/{src/oonirun => }/alembic/__init__.py (100%) rename ooniapi/services/oonirun/{src/oonirun => }/alembic/env.py (100%) rename ooniapi/services/oonirun/{src/oonirun => }/alembic/versions/981d92cf8790_init_tables.py (100%) delete mode 100644 ooniapi/services/oonirun/buildspec-dbmigration.yml delete mode 100644 ooniapi/services/oonirun/src/oonirun/alembic/Readme.md delete mode 100644 ooniapi/services/oonirun/src/oonirun/alembic/old_versions/7d5841cb9549_make_oonirun_link_id_a_string.py delete mode 100644 ooniapi/services/oonirun/src/oonirun/alembic/old_versions/836b3451a168_add_expiration_date_color_columns_drop_.py delete mode 100644 ooniapi/services/oonirun/src/oonirun/alembic/old_versions/9973a7e1f96c_oonirun_nettest_table.py delete mode 100644 ooniapi/services/oonirun/src/oonirun/alembic/old_versions/f96cf47f2791_create_oonirun_db.py delete mode 100644 ooniapi/services/oonirun/src/oonirun/alembic/script.py.mako diff --git a/ooniapi/services/oonirun/.dockerignore b/ooniapi/services/oonirun/.dockerignore new file mode 100644 index 00000000..4f7a82b5 --- /dev/null +++ b/ooniapi/services/oonirun/.dockerignore @@ -0,0 +1,10 @@ +.DS_Store +*.log +*.pyc +*.swp +*.env +.coverage +coverage.xml +dist/ +.venv/ +__pycache__/ diff --git a/ooniapi/services/oonirun/.gitignore b/ooniapi/services/oonirun/.gitignore index d7053580..9a1b4f54 100644 --- a/ooniapi/services/oonirun/.gitignore +++ b/ooniapi/services/oonirun/.gitignore @@ -1,2 +1,3 @@ /dist /coverage_html +*.coverage* diff --git a/ooniapi/services/oonirun/Dockerfile b/ooniapi/services/oonirun/Dockerfile index 99b8ccb2..cef25c48 100644 --- a/ooniapi/services/oonirun/Dockerfile +++ b/ooniapi/services/oonirun/Dockerfile @@ -8,6 +8,10 @@ RUN python -m pip install hatch COPY . /build +# When you build stuff on macOS you end up with ._ files +# https://apple.stackexchange.com/questions/14980/why-are-dot-underscore-files-created-and-how-can-i-avoid-them +RUN find /build -type f -name '._*' -delete + RUN echo "$BUILD_LABEL" > /build/src/oonirun/BUILD_LABEL RUN hatch build @@ -17,9 +21,13 @@ FROM python:3.11-bookworm as runner WORKDIR /app -COPY --from=builder /build /build/dist/*.whl /app/ - +COPY --from=builder /build/README.md /app/ +COPY --from=builder /build/dist/*.whl /app/ RUN pip install /app/*whl && rm /app/*whl +COPY --from=builder /build/alembic/ /app/alembic/ +COPY --from=builder /build/alembic.ini /app/ +RUN rm -rf /app/alembic/__pycache__ + CMD ["uvicorn", "oonirun.main:app", "--host", "0.0.0.0", "--port", "80"] EXPOSE 80 diff --git a/ooniapi/services/oonirun/Makefile b/ooniapi/services/oonirun/Makefile index 0bf8477e..7a8c70ca 100644 --- a/ooniapi/services/oonirun/Makefile +++ b/ooniapi/services/oonirun/Makefile @@ -5,7 +5,7 @@ IMAGE_NAME ?= ooni/api-$(SERVICE_NAME) DATE := $(shell python3 -c "import datetime;print(datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%d'))") GIT_FULL_SHA ?= $(shell git rev-parse HEAD) SHORT_SHA := $(shell echo ${GIT_FULL_SHA} | cut -c1-8) -PKG_VERSION := $(shell cat pyproject.toml | grep -e 'version\s*=' | cut -d '"' -f2) +PKG_VERSION := $(shell hatch version) BUILD_LABEL := $(DATE)-$(SHORT_SHA) VERSION_LABEL = v$(PKG_VERSION) @@ -29,6 +29,7 @@ docker-build: -t ${IMAGE_NAME}:${VERSION_LABEL} \ -t ${IMAGE_NAME}:${ENV_LABEL} \ - + echo "built image: ${IMAGE_NAME}:${BUILD_LABEL} (${IMAGE_NAME}:${VERSION_LABEL} ${IMAGE_NAME}:${ENV_LABEL})" docker-push: # We need to use tar -czh to resolve the common dir symlink diff --git a/ooniapi/services/oonirun/README.md b/ooniapi/services/oonirun/README.md index e69de29b..6041f8df 100644 --- a/ooniapi/services/oonirun/README.md +++ b/ooniapi/services/oonirun/README.md @@ -0,0 +1,15 @@ +## Alembic database migrations + +When you make changes to the DB schema you will have to run the alembic scripts for generating an appropriate migration file. + +This is how you do it: + +1. Create the template migration script +``` +poetry run alembic revision -m "name of the revision" +``` +2. Edit the newly created python file and fill out the `upgrade()` and `downgrade()` function with the relevant code bits +3. You can now run the migration like so: +``` +OONI_PG_URL=postgresql://oonipg:oonipg@localhost/oonipg hatch run alembic upgrade head +``` diff --git a/ooniapi/services/oonirun/src/oonirun/alembic/__init__.py b/ooniapi/services/oonirun/alembic/__init__.py similarity index 100% rename from ooniapi/services/oonirun/src/oonirun/alembic/__init__.py rename to ooniapi/services/oonirun/alembic/__init__.py diff --git a/ooniapi/services/oonirun/src/oonirun/alembic/env.py b/ooniapi/services/oonirun/alembic/env.py similarity index 100% rename from ooniapi/services/oonirun/src/oonirun/alembic/env.py rename to ooniapi/services/oonirun/alembic/env.py diff --git a/ooniapi/services/oonirun/src/oonirun/alembic/versions/981d92cf8790_init_tables.py b/ooniapi/services/oonirun/alembic/versions/981d92cf8790_init_tables.py similarity index 100% rename from ooniapi/services/oonirun/src/oonirun/alembic/versions/981d92cf8790_init_tables.py rename to ooniapi/services/oonirun/alembic/versions/981d92cf8790_init_tables.py diff --git a/ooniapi/services/oonirun/buildspec-dbmigration.yml b/ooniapi/services/oonirun/buildspec-dbmigration.yml deleted file mode 100644 index bb7dd126..00000000 --- a/ooniapi/services/oonirun/buildspec-dbmigration.yml +++ /dev/null @@ -1,26 +0,0 @@ -version: 0.2 -env: - variables: - OONI_CODE_PATH: api/fastapi/ - -phases: - install: - runtime-versions: - python: 3.11 - commands: - - echo "Installing Poetry" - - curl -fsS https://install.python-poetry.org | python - --preview -y - - export PATH="$HOME/.local/bin:$PATH" - - pre_build: - commands: - - aws --version - - build: - commands: - - PROJECT_ROOT=$(pwd) - - cd $OONI_CODE_PATH - - echo "Installing project dependencies with poetry..." - - poetry install --no-root - - export OONI_PG_URL=$(aws secretsmanager get-secret-value --secret-id OONI_PROD_POSTGRES_URL --query SecretString --output text) - - poetry run alembic upgrade head diff --git a/ooniapi/services/oonirun/pyproject.toml b/ooniapi/services/oonirun/pyproject.toml index dc0e1bb3..90f4399c 100644 --- a/ooniapi/services/oonirun/pyproject.toml +++ b/ooniapi/services/oonirun/pyproject.toml @@ -72,10 +72,7 @@ addopts = ["--import-mode=importlib"] branch = true parallel = true source_pkgs = ["oonirun", "tests"] -omit = [ - "src/oonirun/common/*", - "src/oonirun/__about__.py" -] +omit = ["src/oonirun/common/*", "src/oonirun/__about__.py"] [tool.coverage.paths] oonirun = ["src/oonirun"] diff --git a/ooniapi/services/oonirun/src/oonirun/alembic/Readme.md b/ooniapi/services/oonirun/src/oonirun/alembic/Readme.md deleted file mode 100644 index a8d77a90..00000000 --- a/ooniapi/services/oonirun/src/oonirun/alembic/Readme.md +++ /dev/null @@ -1,15 +0,0 @@ -# Alembic database migrations - -When you make changes to the DB schema you will have to run the alembic scripts for generating an appropriate migration file. - -This is how you do it: - -1. Create the template migration script -``` -poetry run alembic revision -m "name of the revision" -``` -2. Edit the newly created python file and fill out the `upgrade()` and `downgrade()` function with the relevant code bits -3. You can now run the migration like so: -``` -OONI_PG_URL=postgresql://oonipg:oonipg@localhost/oonipg poetry run alembic upgrade head -``` diff --git a/ooniapi/services/oonirun/src/oonirun/alembic/old_versions/7d5841cb9549_make_oonirun_link_id_a_string.py b/ooniapi/services/oonirun/src/oonirun/alembic/old_versions/7d5841cb9549_make_oonirun_link_id_a_string.py deleted file mode 100644 index f7dccf63..00000000 --- a/ooniapi/services/oonirun/src/oonirun/alembic/old_versions/7d5841cb9549_make_oonirun_link_id_a_string.py +++ /dev/null @@ -1,37 +0,0 @@ -"""make oonirun link id a string - -Revision ID: 7d5841cb9549 -Revises: 836b3451a168 -Create Date: 2024-02-28 15:41:53.811746 - -""" - -from typing import Sequence, Union - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision: str = "7d5841cb9549" -down_revision: Union[str, None] = "836b3451a168" -branch_labels: Union[str, Sequence[str], None] = None -depends_on: Union[str, Sequence[str], None] = None - - -def upgrade() -> None: - op.execute( - """ - ALTER TABLE oonirun - ALTER COLUMN oonirun_link_id TYPE TEXT USING oonirun_link_id::TEXT - """ - ) - - -def downgrade() -> None: - op.execute( - """ - ALTER TABLE oonirun - ALTER COLUMN oonirun TYPE INTEGER USING oonirun::INTEGER - """ - ) diff --git a/ooniapi/services/oonirun/src/oonirun/alembic/old_versions/836b3451a168_add_expiration_date_color_columns_drop_.py b/ooniapi/services/oonirun/src/oonirun/alembic/old_versions/836b3451a168_add_expiration_date_color_columns_drop_.py deleted file mode 100644 index 2ac09b5c..00000000 --- a/ooniapi/services/oonirun/src/oonirun/alembic/old_versions/836b3451a168_add_expiration_date_color_columns_drop_.py +++ /dev/null @@ -1,32 +0,0 @@ -"""Add expiration_date, color columns. Drop is_archived column. - -Revision ID: 836b3451a168 -Revises: f96cf47f2791 -Create Date: 2024-02-27 09:44:26.833238 - -""" - -from typing import Sequence, Union - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision: str = "836b3451a168" -down_revision: Union[str, None] = "f96cf47f2791" -branch_labels: Union[str, Sequence[str], None] = None -depends_on: Union[str, Sequence[str], None] = None - - -def upgrade() -> None: - op.add_column( - "oonirun", sa.Column("expiration_date", sa.DateTime(), nullable=False) - ) - op.add_column("oonirun", sa.Column("color", sa.String(), nullable=True)) - op.drop_column("oonirun", "is_archived") - - -def downgrade() -> None: - op.drop_column("oonirun", "expiration_date") - op.drop_column("oonirun", "color") diff --git a/ooniapi/services/oonirun/src/oonirun/alembic/old_versions/9973a7e1f96c_oonirun_nettest_table.py b/ooniapi/services/oonirun/src/oonirun/alembic/old_versions/9973a7e1f96c_oonirun_nettest_table.py deleted file mode 100644 index 660128a4..00000000 --- a/ooniapi/services/oonirun/src/oonirun/alembic/old_versions/9973a7e1f96c_oonirun_nettest_table.py +++ /dev/null @@ -1,256 +0,0 @@ -"""oonirun_nettest table - -Revision ID: 9973a7e1f96c -Revises: 7d5841cb9549 -Create Date: 2024-03-08 14:38:53.154821 - -""" - -from datetime import datetime, timezone -from collections import defaultdict -from typing import Dict, List, Sequence, Union, Any -from copy import deepcopy - -from alembic import op -import sqlalchemy as sa -from sqlalchemy.sql import table, column -from sqlalchemy.orm import Session, DeclarativeBase -from sqlalchemy import ForeignKey -from sqlalchemy.orm import Mapped -from sqlalchemy.orm import mapped_column -from sqlalchemy.orm import relationship - - -# revision identifiers, used by Alembic. -revision: str = "9973a7e1f96c" -down_revision: Union[str, None] = "7d5841cb9549" -branch_labels: Union[str, Sequence[str], None] = None -depends_on: Union[str, Sequence[str], None] = None - - -oonirun_nettest_table = table( - "oonirun_nettest", - sa.Column("oonirun_link_id", sa.String(), nullable=False), - sa.Column("revision", sa.Integer(), nullable=False, server_default=sa.text("1")), - sa.Column( - "nettest_index", sa.Integer(), nullable=False, server_default=sa.text("1") - ), - sa.Column("date_created", sa.DateTime(), nullable=True), - sa.Column("test_name", sa.String(), nullable=True), - sa.Column("inputs", sa.JSON(), nullable=True), - sa.Column("options", sa.JSON(), nullable=True), - sa.Column("backend_options", sa.JSON(), nullable=True), - sa.Column( - "is_background_run_enabled_default", - sa.Boolean(), - nullable=True, - server_default=sa.text("false"), - ), - sa.Column( - "is_manual_run_enabled_default", - sa.Boolean(), - nullable=True, - server_default=sa.text("false"), - ), -) - - -def upgrade() -> None: - op.create_table( - "oonirun_nettest", - sa.Column("oonirun_link_id", sa.String(), nullable=False), - sa.Column( - "revision", sa.Integer(), nullable=False, server_default=sa.text("1") - ), - sa.Column( - "nettest_index", sa.Integer(), nullable=False, server_default=sa.text("0") - ), - sa.Column("date_created", sa.DateTime(), nullable=True), - sa.Column("test_name", sa.String(), nullable=True), - sa.Column("inputs", sa.JSON(), nullable=True), - sa.Column("options", sa.JSON(), nullable=True), - sa.Column("backend_options", sa.JSON(), nullable=True), - sa.Column( - "is_background_run_enabled_default", - sa.Boolean(), - nullable=True, - server_default=sa.text("false"), - ), - sa.Column( - "is_manual_run_enabled_default", - sa.Boolean(), - nullable=True, - server_default=sa.text("false"), - ), - sa.PrimaryKeyConstraint("oonirun_link_id", "revision", "nettest_index"), - ) - - bind = op.get_bind() - session = Session(bind=bind) - oonirun_rows = session.execute( - sa.select( - column("oonirun_link_id", sa.String), - column("revision", sa.Integer), - column("nettests", sa.JSON), - column("date_created", sa.DateTime), - ).select_from(table("oonirun")) - ).fetchall() - - for record in oonirun_rows: - nettests_data = record.nettests - for index, nettest in enumerate(nettests_data): - nettest = dict( - oonirun_link_id=record.oonirun_link_id, - revision=record.revision, - nettest_index=index, - date_created=record.date_created, - test_name=nettest["test_name"], - inputs=nettest.get("inputs", []), - options=nettest.get("options", {}), - backend_options=nettest.get("backend_options", {}), - is_background_run_enabled_default=nettest.get( - "is_background_run_enabled", False - ), - is_manual_run_enabled_default=nettest.get( - "is_manual_run_enabled", False - ), - ) - print(nettest) - session.execute(oonirun_nettest_table.insert().values(**nettest)) - session.commit() - - tmp_table_name = "tmp__oonirun_new" - op.create_table( - tmp_table_name, - sa.Column("oonirun_link_id", sa.String(), nullable=False, primary_key=True), - sa.Column("date_created", sa.DateTime(), nullable=False), - sa.Column("date_updated", sa.DateTime(), nullable=False), - sa.Column("creator_account_id", sa.String(), nullable=False), - sa.Column("expiration_date", sa.DateTime(), nullable=False), - sa.Column("name", sa.String(), nullable=False), - sa.Column("short_description", sa.String(), nullable=False), - sa.Column("description", sa.String(), nullable=False), - sa.Column("author", sa.String(), nullable=True), - sa.Column("icon", sa.String(), nullable=True), - sa.Column("color", sa.String(), nullable=True), - sa.Column("name_intl", sa.JSON(), nullable=True), - sa.Column("short_description_intl", sa.JSON(), nullable=True), - sa.Column("description_intl", sa.JSON(), nullable=True), - ) - conn = op.get_bind() - # This SQL query is to deduplicate the oonirun link rows such that we can - # have the highest revision kept so we have the latest metadata for the row - conn.execute( - sa.text( - f""" - INSERT INTO {tmp_table_name} (oonirun_link_id, date_created, - date_updated, creator_account_id, expiration_date, name, - short_description, description, author, icon, color, name_intl, - short_description_intl, description_intl) - SELECT oonirun_link_id, date_created, - date_updated, creator_account_id, expiration_date, name, - short_description, description, author, icon, color, name_intl, - short_description_intl, description_intl - FROM ( - SELECT oonirun_link_id, date_created, - date_updated, creator_account_id, expiration_date, name, - short_description, description, author, icon, color, name_intl, - short_description_intl, description_intl, ROW_NUMBER() OVER (PARTITION BY oonirun_link_id ORDER BY revision DESC) AS rn - FROM oonirun - ) sub - WHERE rn = 1 - """ - ) - ) - op.drop_table("oonirun") - # We then swap these deduplcated table with the new one - op.rename_table(tmp_table_name, "oonirun") - - op.create_foreign_key( - "fk_oonirun_nettest_oonirun_link_id", - "oonirun_nettest", - "oonirun", - ["oonirun_link_id"], - ["oonirun_link_id"], - ) - - -def downgrade() -> None: - """ - XXX This migration is not reversible. - - If you really must do it, check below for code that might work with some massaging. - - op.add_column( - "oonirun", - sa.Column( - "revision", - sa.INTEGER(), - autoincrement=False, - nullable=False, - server_default="1", - ), - ) - op.add_column( - "oonirun", - sa.Column("nettests", sa.JSON(), nullable=False, server_default="{}"), - ) - - bind = op.get_bind() - session = Session(bind=bind) - - # Select distinct `oonirun_link_id` to iterate through each `oonirun` record - distinct_ids = session.execute( - sa.select(column("oonirun_link_id").distinct()).select_from(table("oonirun")) - ).fetchall() - - for oonirun_link_id in distinct_ids: - # Fetch nettest records for each `oonirun_link_id` - nettest_records = session.execute( - sa.select(oonirun_nettest_table) - .where( - oonirun_nettest_table.c.oonirun_link_id - == oonirun_link_id.oonirun_link_id - ) - .order_by( - oonirun_nettest_table.c.revision, oonirun_nettest_table.c.nettest_index - ) - ).fetchall() - - # Construct the JSON structure from the nettest records - records_by_revision: Dict[int, List] = defaultdict(list) - for record in nettest_records: - inputs = [] - for d in record.test_inputs: - if d: - # Kind of ghetto, but anyways we were just handling "url" in the upgrade, so it's better than nothing - inputs.append(list(d.values())[0]) - nettests_json = { - "test_name": record.test_name, - "options": record.test_options, - "backend_options": record.backend_config, - "is_background_run_enabled": record.is_background_run_enabled_default, - "is_manual_run_enabled": record.is_manual_run_enabled_default, - "inputs": inputs, - } - records_by_revision[record.revision].append(nettests_json) - - existing_run_link = session.execute( - sa.select(OONIRunLink).where(OONIRunLink.oonirun_link_id == oonirun_link_id) - ).one() - print(existing_run_link) - - existing_run_link.nettests = records_by_revision.pop(existing_run_link.revision) - session.commit() - - for revision, nettests in records_by_revision.items(): - new_oonirun_link = deepcopy(existing_run_link) - session.expunge(new_oonirun_link) - new_oonirun_link.nettests = nettests - new_oonirun_link.revision = revision - session.add(new_oonirun_link) - session.commit() - - op.drop_table("oonirun_nettest") - """ - raise Exception("This migration is not reversible.") diff --git a/ooniapi/services/oonirun/src/oonirun/alembic/old_versions/f96cf47f2791_create_oonirun_db.py b/ooniapi/services/oonirun/src/oonirun/alembic/old_versions/f96cf47f2791_create_oonirun_db.py deleted file mode 100644 index 5dcded74..00000000 --- a/ooniapi/services/oonirun/src/oonirun/alembic/old_versions/f96cf47f2791_create_oonirun_db.py +++ /dev/null @@ -1,44 +0,0 @@ -"""create oonirun db - -Revision ID: f96cf47f2791 -Revises: -Create Date: 2024-02-15 14:39:47.867136 - -""" - -from typing import Sequence, Union - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision: str = "f96cf47f2791" -down_revision: Union[str, None] = None -branch_labels: Union[str, Sequence[str], None] = None -depends_on: Union[str, Sequence[str], None] = None - - -def upgrade() -> None: - op.create_table( - "oonirun", - sa.Column("oonirun_link_id", sa.Integer, primary_key=True), - sa.Column("revision", sa.Integer(), nullable=False, primary_key=True), - sa.Column("date_created", sa.DateTime(), nullable=False), - sa.Column("date_updated", sa.DateTime(), nullable=False), - sa.Column("creator_account_id", sa.String(), nullable=False), - sa.Column("name", sa.String()), - sa.Column("name_intl", sa.JSON()), - sa.Column("short_description", sa.String()), - sa.Column("short_description_intl", sa.JSON()), - sa.Column("description", sa.String()), - sa.Column("description_intl", sa.JSON()), - sa.Column("author", sa.String()), - sa.Column("icon", sa.String()), - sa.Column("nettests", sa.JSON(), nullable=False), - sa.Column("is_archived", sa.Boolean()), - ) - - -def downgrade() -> None: - op.drop_table("oonirun") diff --git a/ooniapi/services/oonirun/src/oonirun/alembic/script.py.mako b/ooniapi/services/oonirun/src/oonirun/alembic/script.py.mako deleted file mode 100644 index fbc4b07d..00000000 --- a/ooniapi/services/oonirun/src/oonirun/alembic/script.py.mako +++ /dev/null @@ -1,26 +0,0 @@ -"""${message} - -Revision ID: ${up_revision} -Revises: ${down_revision | comma,n} -Create Date: ${create_date} - -""" -from typing import Sequence, Union - -from alembic import op -import sqlalchemy as sa -${imports if imports else ""} - -# revision identifiers, used by Alembic. -revision: str = ${repr(up_revision)} -down_revision: Union[str, None] = ${repr(down_revision)} -branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)} -depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)} - - -def upgrade() -> None: - ${upgrades if upgrades else "pass"} - - -def downgrade() -> None: - ${downgrades if downgrades else "pass"} diff --git a/ooniapi/services/oonirun/tests/conftest.py b/ooniapi/services/oonirun/tests/conftest.py index 0fa1f53e..896ce74d 100644 --- a/ooniapi/services/oonirun/tests/conftest.py +++ b/ooniapi/services/oonirun/tests/conftest.py @@ -25,9 +25,7 @@ def alembic_migration(postgresql): db_url = f"postgresql://{postgresql.info.user}:@{postgresql.info.host}:{postgresql.info.port}/{postgresql.info.dbname}" - migrations_path = ( - pathlib.Path(__file__).parent.parent / "src" / "oonirun" / "alembic" - ).resolve() + migrations_path = (pathlib.Path(__file__).parent.parent / "alembic").resolve() alembic_cfg = Config() alembic_cfg.set_main_option("script_location", str(migrations_path))