From 96640066c54971183d9bf8c34d6ebc23a29daea6 Mon Sep 17 00:00:00 2001 From: ivan-borovets <130386813+ivan-borovets@users.noreply.github.com> Date: Mon, 27 Apr 2026 21:29:15 +0300 Subject: [PATCH 1/2] Migration script --- Makefile | 13 +++++++++++++ README.md | 5 +++++ scripts/makefile/migration.sh | 22 ++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100755 scripts/makefile/migration.sh diff --git a/Makefile b/Makefile index 09f9d46..e421ea1 100644 --- a/Makefile +++ b/Makefile @@ -9,10 +9,14 @@ MAKEFLAGS += --no-print-directory # User-configurable variables (edit this) # INFRA_SERVICES: long-running infra (db, broker, cache, ...) # INFRA_INIT_SERVICES: one-shot services that prepare INFRA_SERVICES +# MIGRATION_DB_SERVICE: transactional db service used by alembic (empty = no migrations) +# STAIRWAY_TEST: path to stairway test (empty = skip stairway step) # ----------------------------- PROJECT_NAME ?= $(notdir $(abspath .)) INFRA_SERVICES ?= db_pg INFRA_INIT_SERVICES ?= +MIGRATION_DB_SERVICE ?= db_pg +STAIRWAY_TEST ?= tests/integration/with_infra/test_stairway.py # ----------------------------- # Internal vars / aliases @@ -24,6 +28,7 @@ DOCKER_ENV := scripts/makefile/docker_env.sh LOCAL_ENV := scripts/makefile/local_env.sh DOCKER_PRUNE := scripts/makefile/docker_prune.sh PYCACHE_DEL := scripts/makefile/pycache_del.sh +MIGRATION := scripts/makefile/migration.sh DISHKA_PLOT_DATA := scripts/dishka/plot_dependencies_data.py # Test stack is isolated by project name @@ -108,6 +113,14 @@ down: stop-all: docker ps -q | xargs -r docker stop +# Migrations +.PHONY: migration +migration: local-env + PROJECT_NAME=$(PROJECT_NAME) \ + MIGRATION_DB_SERVICE=$(MIGRATION_DB_SERVICE) \ + STAIRWAY_TEST=$(STAIRWAY_TEST) \ + $(MIGRATION) "$(msg)" + # Tests (with infra) .PHONY: test-docker test-docker: docker-env diff --git a/README.md b/README.md index b8e0301..ddcb01d 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,11 @@ Test (all paths) make test-docker ``` +Generate a migration +```shell +make migration msg= +``` + See [Makefile](Makefile) for more commands Thanks for your patience and support diff --git a/scripts/makefile/migration.sh b/scripts/makefile/migration.sh new file mode 100755 index 0000000..70c88b6 --- /dev/null +++ b/scripts/makefile/migration.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# The script is called from Makefile +set -eu -o pipefail + +if [ "$#" -ne 1 ] || [ -z "$1" ]; then + echo 'ERROR: msg is required, e.g. make migration msg="add users"' >&2 + exit 2 +fi +slug="$1" + +: "${PROJECT_NAME:?must be set in Makefile}" +: "${MIGRATION_DB_SERVICE:?must be set in Makefile (transactional db service for alembic)}" + +trap 'docker compose -p "$PROJECT_NAME" stop "$MIGRATION_DB_SERVICE" >/dev/null' EXIT + +docker compose -p "$PROJECT_NAME" up -d --build --wait --wait-timeout 180 "$MIGRATION_DB_SERVICE" +alembic upgrade head +alembic revision --autogenerate -m "$slug" + +if [ -n "${STAIRWAY_TEST:-}" ]; then + ALLOW_DESTRUCTIVE_TEST_CLEANUP=1 pytest -s -vv "$STAIRWAY_TEST" +fi From 8bdd4309a1b24f30797604022fcb577ea8ced901 Mon Sep 17 00:00:00 2001 From: ivan-borovets <130386813+ivan-borovets@users.noreply.github.com> Date: Mon, 27 Apr 2026 21:42:27 +0300 Subject: [PATCH 2/2] Update CI --- .github/workflows/ci.yaml | 2 +- Makefile | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index be82dff..d33b9cb 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -22,7 +22,7 @@ jobs: run: uv sync --locked --group dev - name: Check code - run: uv run make check + run: uv run make check-ci - name: Test with Docker env: diff --git a/Makefile b/Makefile index e421ea1..5fdf2cd 100644 --- a/Makefile +++ b/Makefile @@ -65,7 +65,7 @@ pip-audit: $(PIP_AUDIT) # Code quality -.PHONY: slotscheck lint test check +.PHONY: slotscheck lint test check check-ci slotscheck: $(SLOTSCHECK) src @@ -87,6 +87,20 @@ test: check: lint test coverage html +check-ci: + ruff check + ruff format --check + tombi format --check + tombi lint + deptry + $(MAKE) slotscheck + lint-imports + mypy + pytest -v \ + $(PYTEST_PATHS_LIGHT) \ + $(PYTEST_ARGS_COV) + coverage html + # Docker compose .PHONY: docker-env local-env upd up upd-local up-local down stop-all docker-env: