Refactor Alembic configuration and update Docker setup
- Removed the `alembic.ini` file and migrated its configuration to `pyproject.toml` under `[tool.alembic]`, enhancing project organization. - Updated the `Dockerfile` to copy `pyproject.toml` instead of `alembic.ini`, ensuring the new configuration is utilized during the build process. - Modified `entrypoint.sh` to use the new Alembic configuration from `pyproject.toml` for database migrations. - Updated README documentation to reflect the new Alembic configuration and usage instructions.
This commit is contained in:
@@ -22,7 +22,7 @@ COPY --from=builder /usr/local/bin /usr/local/bin
|
|||||||
|
|
||||||
# Application code (duty_teller package + entrypoint, migrations, webapp)
|
# Application code (duty_teller package + entrypoint, migrations, webapp)
|
||||||
ENV PYTHONPATH=/app
|
ENV PYTHONPATH=/app
|
||||||
COPY main.py alembic.ini entrypoint.sh ./
|
COPY main.py pyproject.toml entrypoint.sh ./
|
||||||
COPY duty_teller/ ./duty_teller/
|
COPY duty_teller/ ./duty_teller/
|
||||||
COPY alembic/ ./alembic/
|
COPY alembic/ ./alembic/
|
||||||
COPY webapp/ ./webapp/
|
COPY webapp/ ./webapp/
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ Ensure `.env` exists (e.g. `cp .env.example .env`) and contains `BOT_TOKEN`.
|
|||||||
- `services/` – Business logic (group duty pin, import); accept session from caller.
|
- `services/` – Business logic (group duty pin, import); accept session from caller.
|
||||||
- `utils/` – Shared date, user, and handover helpers.
|
- `utils/` – Shared date, user, and handover helpers.
|
||||||
- `importers/` – Duty-schedule JSON parser.
|
- `importers/` – Duty-schedule JSON parser.
|
||||||
- `alembic/` – Migrations (use `duty_teller.config.DATABASE_URL` and `duty_teller.db.models.Base`).
|
- `alembic/` – Migrations; config in `pyproject.toml` under `[tool.alembic]`; URL and metadata from `duty_teller.config` and `duty_teller.db.models.Base`. Run: `alembic -c pyproject.toml upgrade head`.
|
||||||
- `webapp/` – Miniapp UI (calendar, duty list); served at `/app`.
|
- `webapp/` – Miniapp UI (calendar, duty list); served at `/app`.
|
||||||
- `tests/` – Tests; `helpers.py` provides `make_init_data` for auth tests.
|
- `tests/` – Tests; `helpers.py` provides `make_init_data` for auth tests.
|
||||||
- `pyproject.toml` – Installable package (`pip install -e .`).
|
- `pyproject.toml` – Installable package (`pip install -e .`).
|
||||||
|
|||||||
39
alembic.ini
39
alembic.ini
@@ -1,39 +0,0 @@
|
|||||||
# Alembic config; url is set in env.py from config
|
|
||||||
[alembic]
|
|
||||||
script_location = alembic
|
|
||||||
prepend_sys_path = .
|
|
||||||
version_path_separator = os
|
|
||||||
|
|
||||||
[loggers]
|
|
||||||
keys = root,sqlalchemy,alembic
|
|
||||||
|
|
||||||
[handlers]
|
|
||||||
keys = console
|
|
||||||
|
|
||||||
[formatters]
|
|
||||||
keys = generic
|
|
||||||
|
|
||||||
[logger_root]
|
|
||||||
level = WARN
|
|
||||||
handlers = console
|
|
||||||
qualname =
|
|
||||||
|
|
||||||
[logger_sqlalchemy]
|
|
||||||
level = WARN
|
|
||||||
handlers =
|
|
||||||
qualname = sqlalchemy.engine
|
|
||||||
|
|
||||||
[logger_alembic]
|
|
||||||
level = INFO
|
|
||||||
handlers =
|
|
||||||
qualname = alembic
|
|
||||||
|
|
||||||
[handler_console]
|
|
||||||
class = StreamHandler
|
|
||||||
args = (sys.stderr,)
|
|
||||||
level = NOTSET
|
|
||||||
formatter = generic
|
|
||||||
|
|
||||||
[formatter_generic]
|
|
||||||
format = %(levelname)-5.5s [%(name)s] %(message)s
|
|
||||||
datefmt = %H:%M:%S
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
"""Alembic env: use duty_teller config DATABASE_URL and db.models.Base."""
|
"""Alembic env: use duty_teller config DATABASE_URL and db.models.Base."""
|
||||||
|
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from logging.config import fileConfig
|
|
||||||
|
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from alembic import context
|
from alembic import context
|
||||||
@@ -12,9 +12,15 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|||||||
import duty_teller.config as config
|
import duty_teller.config as config
|
||||||
from duty_teller.db.models import Base
|
from duty_teller.db.models import Base
|
||||||
|
|
||||||
|
# Logging when config is in pyproject.toml (no fileConfig)
|
||||||
|
logging.basicConfig(
|
||||||
|
format="%(levelname)-5.5s [%(name)s] %(message)s",
|
||||||
|
datefmt="%H:%M:%S",
|
||||||
|
level=logging.INFO,
|
||||||
|
)
|
||||||
|
logging.getLogger("sqlalchemy.engine").setLevel(logging.WARN)
|
||||||
|
|
||||||
config_alembic = context.config
|
config_alembic = context.config
|
||||||
if config_alembic.config_file_name is not None:
|
|
||||||
fileConfig(config_alembic.config_file_name)
|
|
||||||
|
|
||||||
database_url = config.DATABASE_URL
|
database_url = config.DATABASE_URL
|
||||||
config_alembic.set_main_option("sqlalchemy.url", database_url)
|
config_alembic.set_main_option("sqlalchemy.url", database_url)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ set -e
|
|||||||
mkdir -p /app/data
|
mkdir -p /app/data
|
||||||
chown botuser:botuser /app/data
|
chown botuser:botuser /app/data
|
||||||
# Apply Alembic migrations (runs as root, creates DB in /app/data)
|
# Apply Alembic migrations (runs as root, creates DB in /app/data)
|
||||||
alembic upgrade head
|
alembic -c pyproject.toml upgrade head
|
||||||
# Ensure new DB file is owned by botuser so the app can write
|
# Ensure new DB file is owned by botuser so the app can write
|
||||||
chown -R botuser:botuser /app/data
|
chown -R botuser:botuser /app/data
|
||||||
# Run the app as botuser
|
# Run the app as botuser
|
||||||
|
|||||||
@@ -33,6 +33,11 @@ dev = [
|
|||||||
where = ["."]
|
where = ["."]
|
||||||
include = ["duty_teller*"]
|
include = ["duty_teller*"]
|
||||||
|
|
||||||
|
[tool.alembic]
|
||||||
|
script_location = "alembic"
|
||||||
|
prepend_sys_path = "."
|
||||||
|
version_path_separator = "os"
|
||||||
|
|
||||||
[tool.black]
|
[tool.black]
|
||||||
line-length = 120
|
line-length = 120
|
||||||
target-version = ["py311"]
|
target-version = ["py311"]
|
||||||
|
|||||||
Reference in New Issue
Block a user