Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

fix(migrations): clean the alembic migrations & scratch revisions #145

Merged
merged 11 commits into from
Mar 30, 2024
2 changes: 1 addition & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
- changed-files:
- any-glob-to-any-file:
- src/alembic.ini
- src/alembic/*
- src/migrations/*

'topic: ci':
- changed-files:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
docker volume rm -f $(docker volume ls -f "dangling=true" -q)
# Update the service
docker compose pull backend gradio
docker compose stop backend gradio && docker compose up -d --wait && docker compose exec backend alembic upgrade head
docker compose stop backend gradio && docker compose up -d --wait
# Check update
docker inspect -f '{{ .Created }}' $(docker compose images -q backend)
docker inspect -f '{{ .Created }}' $(docker compose images -q gradio)
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ jobs:
docker compose -f docker-compose.dev.yml exec -T backend alembic current
docker compose -f docker-compose.dev.yml exec -T backend alembic history --verbose
docker compose -f docker-compose.dev.yml exec -T backend alembic stamp head
docker compose -f docker-compose.dev.yml exec -T backend alembic history --verbose
docker compose -f docker-compose.dev.yml exec -T backend alembic downgrade -1
docker compose -f docker-compose.dev.yml exec -T backend alembic upgrade +1

Expand All @@ -83,4 +82,4 @@ jobs:
owner: 'Quack AI'
starting-year: 2023
ignore-files: 'version.py,__init__.py'
ignore-folders: 'src/tests,src/alembic/versions'
ignore-folders: 'src/tests,src/migrations/versions'
2 changes: 1 addition & 1 deletion docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ services:
- DEBUG=true
volumes:
- ./src/:/app/
command: uvicorn app.main:app --reload --host 0.0.0.0 --port 5050
command: "sh -c 'python app/db.py && uvicorn app.main:app --reload --host 0.0.0.0 --port 5050 --proxy-headers'"
healthcheck:
test: ["CMD-SHELL", "nc -vz localhost 5050"]
interval: 10s
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ services:
- "traefik.http.routers.backend.entrypoints=websecure"
- "traefik.http.routers.backend.tls.certresolver=quackresolver"
- "traefik.http.services.backend.loadbalancer.server.port=5050"
command: uvicorn app.main:app --host 0.0.0.0 --port 5050 --proxy-headers
command: "sh -c 'alembic upgrade head && python app/db.py && uvicorn app.main:app --reload --host 0.0.0.0 --port 5050 --proxy-headers'"
healthcheck:
test: ["CMD-SHELL", "nc -vz localhost 5050"]
interval: 10s
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ services:
- PROMETHEUS_ENABLED=true
volumes:
- ./src/:/app/
command: uvicorn app.main:app --reload --host 0.0.0.0 --port 5050 --proxy-headers
command: "sh -c 'alembic upgrade head && python app/db.py && uvicorn app.main:app --reload --host 0.0.0.0 --port 5050 --proxy-headers'"
healthcheck:
test: ["CMD-SHELL", "nc -vz localhost 5050"]
interval: 10s
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ known-third-party = ["fastapi"]
".github/**.py" = ["D", "T201", "ANN"]
"client/docs/**.py" = ["E402"]
"src/tests/**.py" = ["D103", "CPY001", "S101", "T201", "ANN001", "ANN201", "ARG001"]
"src/alembic/versions/**.py" = ["CPY001"]
"src/alembic/**.py" = ["ANN"]
"src/migrations/versions/**.py" = ["CPY001"]
"src/migrations/**.py" = ["ANN"]
"client/tests/**.py" = ["D103", "CPY001", "S101"]
"src/app/main.py" = ["ANN"]
"src/app/schemas/**.py" = ["A"]
Expand Down
2 changes: 1 addition & 1 deletion src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ RUN set -eux \

# copy project
COPY src/alembic.ini /app/alembic.ini
COPY src/alembic /app/alembic
COPY src/migrations /app/migrations
COPY src/app /app/app
64 changes: 53 additions & 11 deletions src/alembic.ini
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@

[alembic]
# path to migration scripts
script_location = alembic
script_location = migrations

# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s
file_template = %%(year)d-%%(month).2d-%%(day).2d-%%(hour).2d-%%(minute).2d_%%(rev)s
# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
# Uncomment the line below if you want the files to be prepended with date and time
file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s

# timezone to use when rendering the date
# within the migration file as well as the filename.
# sys.path path, will be prepended to sys.path if present.
# defaults to the current working directory.
prepend_sys_path = .

# timezone to use when rendering the date within the migration file
# as well as the filename.
# If specified, requires the python-dateutil library that can be
# installed by adding `alembic[tz]` to the pip requirements
# string value is passed to dateutil.tz.gettz()
# leave blank for localtime
# timezone =

# max length of characters to apply to the
# "slug" field
#truncate_slug_length = 40
# truncate_slug_length = 40

# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
Expand All @@ -27,15 +33,51 @@ file_template = %%(year)d-%%(month).2d-%%(day).2d-%%(hour).2d-%%(minute).2d_%%(r
# versions/ directory
# sourceless = false

# version location specification; this defaults
# to alembic/versions. When using multiple version
# directories, initial revisions must be specified with --version-path
# version_locations = %(here)s/bar %(here)s/bat alembic/versions
# version location specification; This defaults
# to migrations/versions. When using multiple version
# directories, initial revisions must be specified with --version-path.
# The path separator used here should be the separator specified by "version_path_separator" below.
# version_locations = %(here)s/bar:%(here)s/bat:migrations/versions

# version path separator; As mentioned above, this is the character used to split
# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.
# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas.
# Valid values for version_path_separator are:
#
# version_path_separator = :
# version_path_separator = ;
# version_path_separator = space
version_path_separator = os # Use os.pathsep. Default configuration used for new projects.

# set to 'true' to search source files recursively
# in each "version_locations" directory
# new in Alembic version 1.10
# recursive_version_locations = false

# the output encoding used when revision files
# are written from script.py.mako
# output_encoding = utf-8

# sqlalchemy.url = driver://user:pass@localhost/dbname


[post_write_hooks]
# post_write_hooks defines scripts or Python functions that are run
# on newly generated revision scripts. See the documentation for further
# detail and examples

# format using "black" - use the console_scripts runner, against the "black" entrypoint
# hooks = black
# black.type = console_scripts
# black.entrypoint = black
# black.options = -l 79 REVISION_SCRIPT_FILENAME

# lint with attempts to fix using "ruff" - use the exec runner, execute a binary
# hooks = ruff
# ruff.type = exec
# ruff.executable = %(here)s/.venv/bin/ruff
# ruff.options = --fix REVISION_SCRIPT_FILENAME

# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic
Expand Down
25 changes: 0 additions & 25 deletions src/alembic/README.md

This file was deleted.

26 changes: 0 additions & 26 deletions src/alembic/script.py.mako

This file was deleted.

57 changes: 0 additions & 57 deletions src/alembic/versions/2023-11-07-15-35_eb1a6567456c.py

This file was deleted.

90 changes: 0 additions & 90 deletions src/alembic/versions/2024-02-23-11-56_4c08af871a9e.py

This file was deleted.

Loading
Loading