Skip to content
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

[Issue #2976] Run analytics migrations like the API does them #2978

Merged
merged 9 commits into from
Nov 21, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/ci-analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ jobs:
- name: Run linting
run: make lint

- name: Run database initialization
run: docker compose down --volumes && make init-db
- name: Run database migrations
run: docker compose down --volumes && make db-migrate

- name: Run tests
run: make test-audit
Expand Down
6 changes: 3 additions & 3 deletions analytics/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ lint: ## runs code quality checks
# Data Commands #
#################

init-db:
@echo "=> Initializing the database schema"
db-migrate:
@echo "=> Migrating the database schema"
@echo "====================================================="
$(POETRY) analytics etl initialize_database
$(POETRY) analytics etl db_migrate
@echo "====================================================="

gh-transform-and-load:
Expand Down
3 changes: 2 additions & 1 deletion analytics/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ version = "0.1.0"

[tool.poetry.scripts]
analytics = "analytics.cli:app"
db-migrate = "src.analytics.cli:db_migrate"

[tool.poetry.dependencies]
dynaconf = "^3.2.4"
kaleido = "0.2.1"
notebook = "^7.0.0" # Goal is to replace this with another method of presenting charts
notebook = "^7.0.0" # Goal is to replace this with another method of presenting charts
pandas = "^2.0.3"
pandas-stubs = "^2.0.2.230605"
plotly = "^5.15.0"
Expand Down
8 changes: 4 additions & 4 deletions analytics/src/analytics/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,12 @@ def export_json_to_database(delivery_file: Annotated[str, ISSUE_FILE_ARG]) -> No
# ===========================================================


@etl_app.command(name="initialize_database")
@ecs_background_task("initialize_database")
def initialize_database() -> None:
@etl_app.command(name="db_migrate")
@ecs_background_task("db_migrate")
def migrate_database() -> None:
"""Initialize etl database."""
logger.info("initializing database")
etldb.initialize_database()
etldb.migrate_database()
logger.info("done")


Expand Down
4 changes: 2 additions & 2 deletions analytics/src/analytics/integrations/etldb/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Read and write data from/to delivery metrics database."""

__all__ = [
"initialize_database",
"migrate_database",
"sync_data",
]

from analytics.integrations.etldb.main import (
initialize_database,
migrate_database,
sync_data,
)
2 changes: 1 addition & 1 deletion analytics/src/analytics/integrations/etldb/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
VERBOSE = False


def initialize_database() -> None:
def migrate_database() -> None:
"""
Create and/or update an etl database by applying a sequential set of migration scripts.

Expand Down
2 changes: 1 addition & 1 deletion analytics/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def test_init_db(self):
# setup - create command
command = [
"etl",
"initialize_database",
"db_migrate",
]
# execution
result = runner.invoke(app, command)
Expand Down
5 changes: 0 additions & 5 deletions infra/analytics/app-config/env-config/scheduled_jobs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,5 @@ locals {
schedule_expression = "rate(1 days)"
state = "ENABLED"
}
init-etldb = {
task_command = ["make", "init-db"]
schedule_expression = "rate(1 days)"
state = "ENABLED"
}
}
}
6 changes: 1 addition & 5 deletions infra/analytics/app-config/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ output "environment_configs" {
value = local.environment_configs
}

# This variable is slightly misnamed. It should really be called "has_migrations".
# It controls whether or not the `run-database-migrations.sh` script tries to run database
# migrations. The entire analytics application is going to have its schema controlled
# via ETL jobs, so we don't need to run migrations in the same way as the API.
output "has_database" {
value = false
value = true
}