mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-19 05:09:40 +02:00
feat: Move alembic config into mealie package for easier distribution (#4329)
This commit is contained in:
parent
f1e9615efd
commit
a6cbf1308e
48 changed files with 24 additions and 37 deletions
|
@ -151,7 +151,7 @@ tasks:
|
||||||
py:migrate:
|
py:migrate:
|
||||||
desc: generates a new database migration file e.g. task py:migrate -- "add new column"
|
desc: generates a new database migration file e.g. task py:migrate -- "add new column"
|
||||||
cmds:
|
cmds:
|
||||||
- poetry run alembic revision --autogenerate -m "{{ .CLI_ARGS }}"
|
- poetry run alembic --config mealie/alembic/alembic.ini revision --autogenerate -m "{{ .CLI_ARGS }}"
|
||||||
- task: py:format
|
- task: py:format
|
||||||
|
|
||||||
ui:build:
|
ui:build:
|
||||||
|
|
|
@ -109,10 +109,6 @@ COPY --from=crfpp /usr/local/bin/crf_test /usr/local/bin/crf_test
|
||||||
COPY ./mealie $MEALIE_HOME/mealie
|
COPY ./mealie $MEALIE_HOME/mealie
|
||||||
COPY ./poetry.lock ./pyproject.toml $MEALIE_HOME/
|
COPY ./poetry.lock ./pyproject.toml $MEALIE_HOME/
|
||||||
|
|
||||||
# Alembic
|
|
||||||
COPY ./alembic $MEALIE_HOME/alembic
|
|
||||||
COPY ./alembic.ini $MEALIE_HOME/
|
|
||||||
|
|
||||||
# venv already has runtime deps installed we get a quicker install
|
# venv already has runtime deps installed we get a quicker install
|
||||||
WORKDIR $MEALIE_HOME
|
WORKDIR $MEALIE_HOME
|
||||||
RUN . $VENV_PATH/bin/activate && poetry install -E pgsql --only main
|
RUN . $VENV_PATH/bin/activate && poetry install -E pgsql --only main
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
[alembic]
|
[alembic]
|
||||||
# path to migration scripts
|
# path to migration scripts
|
||||||
script_location = alembic
|
script_location = %(here)s
|
||||||
|
|
||||||
# template used to generate migration files
|
# template used to generate migration files
|
||||||
file_template = %%(year)d-%%(month).2d-%%(day).2d-%%(hour).2d.%%(minute).2d.%%(second).2d_%%(rev)s_%%(slug)s
|
file_template = %%(year)d-%%(month).2d-%%(day).2d-%%(hour).2d.%%(minute).2d.%%(second).2d_%%(rev)s_%%(slug)s
|
|
@ -1,9 +1,9 @@
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
from alembic import context
|
||||||
|
|
||||||
import mealie.db.models._all_models # noqa: F401
|
import mealie.db.models._all_models # noqa: F401
|
||||||
from alembic import context
|
|
||||||
from mealie.core.config import get_app_settings
|
from mealie.core.config import get_app_settings
|
||||||
from mealie.db.models._model_base import SqlAlchemyBase
|
from mealie.db.models._model_base import SqlAlchemyBase
|
||||||
|
|
|
@ -6,9 +6,9 @@ Create Date: ${create_date}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
from alembic import op
|
||||||
|
|
||||||
import mealie.db.migration_types
|
import mealie.db.migration_types
|
||||||
from alembic import op
|
|
||||||
% if imports:
|
% if imports:
|
||||||
${imports}
|
${imports}
|
||||||
% endif
|
% endif
|
|
@ -9,10 +9,10 @@ Create Date: 2024-02-23 16:15:07.115641
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
from alembic import op
|
||||||
from sqlalchemy import orm
|
from sqlalchemy import orm
|
||||||
|
|
||||||
import mealie.db.migration_types
|
import mealie.db.migration_types
|
||||||
from alembic import op
|
|
||||||
from mealie.core.root_logger import get_logger
|
from mealie.core.root_logger import get_logger
|
||||||
|
|
||||||
logger = get_logger()
|
logger = get_logger()
|
|
@ -12,10 +12,10 @@ from typing import Any
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
from alembic import op
|
||||||
from sqlalchemy import orm
|
from sqlalchemy import orm
|
||||||
|
|
||||||
import mealie.db.migration_types
|
import mealie.db.migration_types
|
||||||
from alembic import op
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
# revision identifiers, used by Alembic.
|
||||||
revision = "d7c6efd2de42"
|
revision = "d7c6efd2de42"
|
|
@ -7,9 +7,9 @@ Create Date: 2024-04-07 01:05:20.816270
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
from alembic import op
|
||||||
|
|
||||||
import mealie.db.migration_types
|
import mealie.db.migration_types
|
||||||
from alembic import op
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
# revision identifiers, used by Alembic.
|
||||||
revision = "7788478a0338"
|
revision = "7788478a0338"
|
|
@ -7,9 +7,8 @@ Create Date: 2024-06-22 10:17:03.323966
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
from sqlalchemy import orm
|
|
||||||
|
|
||||||
from alembic import op
|
from alembic import op
|
||||||
|
from sqlalchemy import orm
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
# revision identifiers, used by Alembic.
|
||||||
revision = "32d69327997b"
|
revision = "32d69327997b"
|
|
@ -12,11 +12,11 @@ from typing import Any
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
from alembic import op
|
||||||
from slugify import slugify
|
from slugify import slugify
|
||||||
from sqlalchemy import orm
|
from sqlalchemy import orm
|
||||||
|
|
||||||
import mealie.db.migration_types
|
import mealie.db.migration_types
|
||||||
from alembic import op
|
|
||||||
from mealie.core.config import get_app_settings
|
from mealie.core.config import get_app_settings
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
# revision identifiers, used by Alembic.
|
|
@ -9,7 +9,6 @@ Create Date: 2024-09-02 21:39:49.210355
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
|
||||||
from alembic import op
|
from alembic import op
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
# revision identifiers, used by Alembic.
|
|
@ -7,9 +7,9 @@ Create Date: 2024-09-18 14:52:55.831540
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
from alembic import op
|
||||||
|
|
||||||
import mealie.db.migration_types
|
import mealie.db.migration_types
|
||||||
from alembic import op
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
# revision identifiers, used by Alembic.
|
||||||
revision = "1fe4bd37ccc8"
|
revision = "1fe4bd37ccc8"
|
|
@ -7,7 +7,6 @@ Create Date: 2024-10-01 14:17:00.611398
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
|
||||||
from alembic import op
|
from alembic import op
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
# revision identifiers, used by Alembic.
|
|
@ -7,9 +7,9 @@ Create Date: 2024-10-08 21:17:31.601903
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
from alembic import op
|
||||||
from sqlalchemy import orm
|
from sqlalchemy import orm
|
||||||
|
|
||||||
from alembic import op
|
|
||||||
from mealie.db.models._model_utils import guid
|
from mealie.db.models._model_utils import guid
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
# revision identifiers, used by Alembic.
|
|
@ -7,7 +7,6 @@ Create Date: 2024-10-20 09:47:46.844436
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
|
||||||
from alembic import op
|
from alembic import op
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
# revision identifiers, used by Alembic.
|
|
@ -7,9 +7,9 @@ Create Date: 2024-10-23 15:50:59.888793
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
from alembic import op
|
||||||
from sqlalchemy import orm
|
from sqlalchemy import orm
|
||||||
|
|
||||||
from alembic import op
|
|
||||||
from mealie.db.models._model_utils.guid import GUID
|
from mealie.db.models._model_utils.guid import GUID
|
||||||
from mealie.services.scraper.cleaner import clean_yield
|
from mealie.services.scraper.cleaner import clean_yield
|
||||||
|
|
|
@ -3,11 +3,11 @@ from collections.abc import Callable
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
from sqlalchemy import engine, orm, text
|
|
||||||
|
|
||||||
from alembic import command, config, script
|
from alembic import command, config, script
|
||||||
from alembic.config import Config
|
from alembic.config import Config
|
||||||
from alembic.runtime import migration
|
from alembic.runtime import migration
|
||||||
|
from sqlalchemy import engine, orm, text
|
||||||
|
|
||||||
from mealie.core import root_logger
|
from mealie.core import root_logger
|
||||||
from mealie.core.config import get_app_settings
|
from mealie.core.config import get_app_settings
|
||||||
from mealie.db.db_setup import session_context
|
from mealie.db.db_setup import session_context
|
||||||
|
@ -22,7 +22,7 @@ from mealie.schema.user.user import GroupBase, GroupInDB
|
||||||
from mealie.services.group_services.group_service import GroupService
|
from mealie.services.group_services.group_service import GroupService
|
||||||
from mealie.services.household_services.household_service import HouseholdService
|
from mealie.services.household_services.household_service import HouseholdService
|
||||||
|
|
||||||
PROJECT_DIR = Path(__file__).parent.parent.parent
|
ALEMBIC_DIR = Path(__file__).parent.parent / "alembic"
|
||||||
|
|
||||||
logger = root_logger.get_logger()
|
logger = root_logger.get_logger()
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ def main():
|
||||||
if max_retry == 0:
|
if max_retry == 0:
|
||||||
raise ConnectionError("Database connection failed - exiting application.")
|
raise ConnectionError("Database connection failed - exiting application.")
|
||||||
|
|
||||||
alembic_cfg_path = os.getenv("ALEMBIC_CONFIG_FILE", default=str(PROJECT_DIR / "alembic.ini"))
|
alembic_cfg_path = os.getenv("ALEMBIC_CONFIG_FILE", default=str(ALEMBIC_DIR / "alembic.ini"))
|
||||||
|
|
||||||
if not os.path.isfile(alembic_cfg_path):
|
if not os.path.isfile(alembic_cfg_path):
|
||||||
raise Exception("Provided alembic config path doesn't exist")
|
raise Exception("Provided alembic config path doesn't exist")
|
||||||
|
|
|
@ -3,25 +3,23 @@ import os
|
||||||
import uuid
|
import uuid
|
||||||
from logging import Logger
|
from logging import Logger
|
||||||
from os import path
|
from os import path
|
||||||
from pathlib import Path
|
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
from alembic import command
|
||||||
|
from alembic.config import Config
|
||||||
from fastapi.encoders import jsonable_encoder
|
from fastapi.encoders import jsonable_encoder
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from sqlalchemy import Connection, ForeignKey, ForeignKeyConstraint, MetaData, Table, create_engine, insert, text
|
from sqlalchemy import Connection, ForeignKey, ForeignKeyConstraint, MetaData, Table, create_engine, insert, text
|
||||||
from sqlalchemy.engine import base
|
from sqlalchemy.engine import base
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
|
|
||||||
from alembic import command
|
|
||||||
from alembic.config import Config
|
|
||||||
from mealie.db import init_db
|
from mealie.db import init_db
|
||||||
from mealie.db.fixes.fix_migration_data import fix_migration_data
|
from mealie.db.fixes.fix_migration_data import fix_migration_data
|
||||||
|
from mealie.db.init_db import ALEMBIC_DIR
|
||||||
from mealie.db.models._model_utils.guid import GUID
|
from mealie.db.models._model_utils.guid import GUID
|
||||||
from mealie.services._base_service import BaseService
|
from mealie.services._base_service import BaseService
|
||||||
|
|
||||||
PROJECT_DIR = Path(__file__).parent.parent.parent.parent
|
|
||||||
|
|
||||||
|
|
||||||
class ForeignKeyDisabler:
|
class ForeignKeyDisabler:
|
||||||
def __init__(self, connection: Connection, dialect_name: str, *, logger: Logger | None = None):
|
def __init__(self, connection: Connection, dialect_name: str, *, logger: Logger | None = None):
|
||||||
|
@ -193,15 +191,12 @@ class AlchemyExporter(BaseService):
|
||||||
alembic_data = db_dump["alembic_version"]
|
alembic_data = db_dump["alembic_version"]
|
||||||
alembic_version = alembic_data[0]["version_num"]
|
alembic_version = alembic_data[0]["version_num"]
|
||||||
|
|
||||||
alembic_cfg_path = os.getenv("ALEMBIC_CONFIG_FILE", default=str(PROJECT_DIR / "alembic.ini"))
|
alembic_cfg_path = os.getenv("ALEMBIC_CONFIG_FILE", default=str(ALEMBIC_DIR / "alembic.ini"))
|
||||||
|
|
||||||
if not path.isfile(alembic_cfg_path):
|
if not path.isfile(alembic_cfg_path):
|
||||||
raise Exception("Provided alembic config path doesn't exist")
|
raise Exception("Provided alembic config path doesn't exist")
|
||||||
|
|
||||||
alembic_cfg = Config(alembic_cfg_path)
|
alembic_cfg = Config(alembic_cfg_path)
|
||||||
# alembic's file resolver wants to use the "mealie" subdirectory when called from within the server package
|
|
||||||
# Just override this to use the correct migrations path
|
|
||||||
alembic_cfg.set_main_option("script_location", path.join(PROJECT_DIR, "alembic"))
|
|
||||||
command.upgrade(alembic_cfg, alembic_version)
|
command.upgrade(alembic_cfg, alembic_version)
|
||||||
|
|
||||||
del db_dump["alembic_version"]
|
del db_dump["alembic_version"]
|
||||||
|
|
|
@ -158,8 +158,8 @@ select = [
|
||||||
|
|
||||||
[tool.ruff.lint.per-file-ignores]
|
[tool.ruff.lint.per-file-ignores]
|
||||||
"__init__.py" = ["E402", "E501"]
|
"__init__.py" = ["E402", "E501"]
|
||||||
"alembic/versions/2022*" = ["E501"]
|
"mealie/alembic/versions/2022*" = ["E501", "I001"]
|
||||||
"alembic/versions/2023*" = ["E501"]
|
"mealie/alembic/versions/2023*" = ["E501", "I001"]
|
||||||
"dev/scripts/all_recipes_stress_test.py" = ["E501"]
|
"dev/scripts/all_recipes_stress_test.py" = ["E501"]
|
||||||
"ldap_provider.py" = ["UP032"]
|
"ldap_provider.py" = ["UP032"]
|
||||||
"tests/conftest.py" = ["E402"]
|
"tests/conftest.py" = ["E402"]
|
||||||
|
|
|
@ -2,9 +2,9 @@ import importlib.util
|
||||||
import pathlib
|
import pathlib
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
|
|
||||||
from mealie.db.init_db import PROJECT_DIR
|
from mealie.db.init_db import ALEMBIC_DIR
|
||||||
|
|
||||||
ALEMBIC_MIGRATIONS = PROJECT_DIR / "alembic" / "versions"
|
ALEMBIC_MIGRATIONS = ALEMBIC_DIR / "versions"
|
||||||
|
|
||||||
|
|
||||||
def import_file(module_name: str, file_path: pathlib.Path):
|
def import_file(module_name: str, file_path: pathlib.Path):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue