From 69d6fa7c158684542bb9f63ce933e2298ccaf9c1 Mon Sep 17 00:00:00 2001 From: maxDorninger <97409287+maxDorninger@users.noreply.github.com> Date: Sun, 1 Jun 2025 22:45:16 +0200 Subject: [PATCH] add automatic alembic migrations to docker images --- Dockerfile | 2 +- alembic/env.py | 8 ------ .../93fb07842385_initial_migration.py | 13 ++------- media_manager/indexer/config.py | 4 +-- pyproject.toml | 1 + uv.lock | 28 +++++++++++++++++++ 6 files changed, 34 insertions(+), 22 deletions(-) diff --git a/Dockerfile b/Dockerfile index a5e5126..2a6a824 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,4 +20,4 @@ COPY pyproject.toml . COPY uv.lock . RUN uv sync --locked EXPOSE 8000 -CMD ["uv", "run", "fastapi", "run", "/app/media_manager/main.py"] +CMD uv run alembic upgrade head && uv run fastapi run /app/media_manager/main.py \ No newline at end of file diff --git a/alembic/env.py b/alembic/env.py index 82924fd..4b45617 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -10,14 +10,6 @@ from pydantic_settings import BaseSettings, SettingsConfigDict from sqlalchemy import engine_from_config from sqlalchemy import pool -from dotenv import load_dotenv -from pathlib import Path - -env_path = Path(__file__).parent.parent.parent / Path("res") / Path(".env") -print(env_path) -load_dotenv(dotenv_path=env_path) - - # this is the Alembic Config object, which provides # access to the values within the .ini file in use. config = context.config diff --git a/alembic/versions/93fb07842385_initial_migration.py b/alembic/versions/93fb07842385_initial_migration.py index 7cf77e9..7963983 100644 --- a/alembic/versions/93fb07842385_initial_migration.py +++ b/alembic/versions/93fb07842385_initial_migration.py @@ -21,21 +21,12 @@ depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: """Upgrade schema.""" # ### commands auto generated by Alembic - please adjust! ### - op.drop_column("season", "size") + # ### end Alembic commands ### def downgrade() -> None: """Downgrade schema.""" # ### commands auto generated by Alembic - please adjust! ### - op.add_column( - "season", - sa.Column( - "size", - sa.INTEGER(), - server_default=sa.text("0"), - autoincrement=False, - nullable=False, - ), - ) + # ### end Alembic commands ### diff --git a/media_manager/indexer/config.py b/media_manager/indexer/config.py index 861e21e..d2f2f6d 100644 --- a/media_manager/indexer/config.py +++ b/media_manager/indexer/config.py @@ -4,14 +4,14 @@ from pydantic_settings import BaseSettings, SettingsConfigDict class ProwlarrConfig(BaseSettings): model_config = SettingsConfigDict(env_prefix="PROWLARR_") enabled: bool | None = False - api_key: str | None + api_key: str | None = None url: str = "http://localhost:9696" class JackettConfig(BaseSettings): model_config = SettingsConfigDict(env_prefix="JACKETT_") enabled: bool | None = False - api_key: str | None + api_key: str | None = None url: str = "http://localhost:9696" indexers: list[str] = [ "all" diff --git a/pyproject.toml b/pyproject.toml index ec1830d..770b1ee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,4 +27,5 @@ dependencies = [ "uvicorn>=0.34.2", "fastapi-utils>=0.8.0", "apscheduler>=3.11.0", + "alembic>=1.16.1", ] diff --git a/uv.lock b/uv.lock index b6ef704..31e1c7f 100644 --- a/uv.lock +++ b/uv.lock @@ -2,6 +2,20 @@ version = 1 revision = 2 requires-python = ">=3.13" +[[package]] +name = "alembic" +version = "1.16.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "mako" }, + { name = "sqlalchemy" }, + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/20/89/bfb4fe86e3fc3972d35431af7bedbc60fa606e8b17196704a1747f7aa4c3/alembic-1.16.1.tar.gz", hash = "sha256:43d37ba24b3d17bc1eb1024fe0f51cd1dc95aeb5464594a02c6bb9ca9864bfa4", size = 1955006, upload-time = "2025-05-21T23:11:05.991Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/31/59/565286efff3692c5716c212202af61466480f6357c4ae3089d4453bff1f3/alembic-1.16.1-py3-none-any.whl", hash = "sha256:0cdd48acada30d93aa1035767d67dff25702f8de74d7c3919f2e8492c8db2e67", size = 242488, upload-time = "2025-05-21T23:11:07.783Z" }, +] + [[package]] name = "annotated-types" version = "0.7.0" @@ -533,6 +547,18 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/b7/c0/4bc973defd1270b89ccaae04cef0d5fa3ea85b59b108ad2c08aeea9afb76/makefun-1.16.0-py2.py3-none-any.whl", hash = "sha256:43baa4c3e7ae2b17de9ceac20b669e9a67ceeadff31581007cca20a07bbe42c4", size = 22923, upload-time = "2025-05-09T15:00:41.042Z" }, ] +[[package]] +name = "mako" +version = "1.3.10" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "markupsafe" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/9e/38/bd5b78a920a64d708fe6bc8e0a2c075e1389d53bef8413725c63ba041535/mako-1.3.10.tar.gz", hash = "sha256:99579a6f39583fa7e5630a28c3c1f440e4e97a414b80372649c0ce338da2ea28", size = 392474, upload-time = "2025-04-10T12:44:31.16Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/87/fb/99f81ac72ae23375f22b7afdb7642aba97c00a713c217124420147681a2f/mako-1.3.10-py3-none-any.whl", hash = "sha256:baef24a52fc4fc514a0887ac600f9f1cff3d82c61d4d700a1fa84d597b88db59", size = 78509, upload-time = "2025-04-10T12:50:53.297Z" }, +] + [[package]] name = "markdown-it-py" version = "3.0.0" @@ -587,6 +613,7 @@ name = "mediamanager" version = "0.1.0" source = { virtual = "." } dependencies = [ + { name = "alembic" }, { name = "apscheduler" }, { name = "bencoder" }, { name = "cachetools" }, @@ -614,6 +641,7 @@ dependencies = [ [package.metadata] requires-dist = [ + { name = "alembic", specifier = ">=1.16.1" }, { name = "apscheduler", specifier = ">=3.11.0" }, { name = "bencoder", specifier = ">=0.2.0" }, { name = "cachetools", specifier = ">=6.0.0" },