mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-03-12 04:35:35 -07:00
feat: Move alembic config into mealie package for easier distribution (#4329)
This commit is contained in:
parent
f1e9615efd
commit
a6cbf1308e
Taskfile.ymlpyproject.toml
docker
mealie
alembic
READMEalembic.inienv.pyscript.py.mako
versions
2022-02-21-19.56.24_6b0f5f32d602_initial_tables.py2022-03-23-17.43.34_263dd6707191_convert_quantity_from_integer_to_float.py2022-03-27-19.30.28_f1a2dbee5fe9_add_original_text_column_to_recipes_.py2022-03-31-19.19.55_59eb59135381_add_tags_to_cookbooks.py2022-04-03-10.48.51_09dfc897ad62_add_require_all_for_cookbook_filters.py2022-06-01-11.12.06_ab0bae02578f_add_use_abbreviation_column_to_.py2022-06-15-21.05.34_f30cf048c228_add_new_webhook_fields.py2022-08-12-19.05.59_188374910655_add_login_attemps_and_locked_at_field_.py2022-08-13-17.07.07_089bfa50d0ed_add_is_ocr_recipe_column_to_recipes.py2022-08-29-13.57.40_44e8d670719d_add_extras_to_shopping_lists_list_items_.py2022-09-27-14.53.14_2ea7a807915c_add_recipe_timeline_events_table.py2022-11-03-13.10.24_1923519381ad_renamed_timeline_event_message_and_.py2022-11-22-03.42.45_167eb69066ad_add_recipe_scale_to_shopping_list_item_.py2023-01-21-16.54.44_165d943c64ee_add_related_user_to_mealplan.py2023-02-07-20.57.21_ff5f73b01a7a_add_missing_foreign_key_and_order_.py2023-02-10-21.18.32_16160bf731a0_add_more_indices_necessary_for_search.py2023-02-14-20.45.41_5ab195a474eb_add_normalized_search_properties.py2023-02-21-22.03.19_b04a08da2108_added_shopping_list_label_settings.py2023-02-22-21.45.52_38514b39a824_add_auth_method_to_user_table.py2023-04-13-06.47.04_b3dbb554ba53_postgres_fuzzy_search.py2023-08-06-21.00.34_04ac51cbe9a4_added_group_slug.py2023-08-14-19.30.49_1825b5225403_added_recipe_note_to_shopping_list_.py2023-08-15-16.25.07_bcfdad6b7355_remove_tool_name_and_slug_unique_.py2023-09-01-14.55.42_0341b154f79a_added_normalized_unit_and_food_names.py2023-10-04-14.29.26_dded3119c1fe_added_unique_constraints.py2023-10-19-19.22.55_ba1e4a6cfe99_added_plural_names_and_alias_tables_for_.py2024-02-23-16.15.07_2298bb460ffd_added_user_to_shopping_list.py2024-03-10-05.08.32_09aba125b57a_add_oidc_auth_method.py2024-03-18-02.28.15_d7c6efd2de42_migrate_favorites_and_ratings_to_user_.py2024-04-07-01.05.20_7788478a0338_add_group_recipe_actions.py2024-06-22-10.17.03_32d69327997b_add_staple_flag_to_foods.py2024-07-12-16.16.29_feecc8ffb956_add_households.py2024-09-02-21.39.49_be568e39ffdf_added_household_recipe_lock_setting_and_.py2024-09-18-14.52.55_1fe4bd37ccc8_add_households_filter_to_meal_plans.py2024-10-01-14.17.00_602927e1013e_add_the_rest_of_the_schema_org_.py2024-10-08-21.17.31_86054b40fd06_added_query_filter_string_to_cookbook_.py2024-10-20-09.47.46_3897397b4631_add_summary_to_recipe_instructions.py2024-10-23-15.50.59_b1020f328e98_add_recipe_yield_quantity.py
db
services/backups_v2
tests/utils
@ -151,7 +151,7 @@ tasks:
|
||||
py:migrate:
|
||||
desc: generates a new database migration file e.g. task py:migrate -- "add new column"
|
||||
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
|
||||
|
||||
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 ./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
|
||||
WORKDIR $MEALIE_HOME
|
||||
RUN . $VENV_PATH/bin/activate && poetry install -E pgsql --only main
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
[alembic]
|
||||
# path to migration scripts
|
||||
script_location = alembic
|
||||
script_location = %(here)s
|
||||
|
||||
# template used to generate migration files
|
||||
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
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import context
|
||||
|
||||
import mealie.db.models._all_models # noqa: F401
|
||||
from alembic import context
|
||||
from mealie.core.config import get_app_settings
|
||||
from mealie.db.models._model_base import SqlAlchemyBase
|
||||
|
@ -6,9 +6,9 @@ Create Date: ${create_date}
|
||||
|
||||
"""
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
import mealie.db.migration_types
|
||||
from alembic import op
|
||||
% if imports:
|
||||
${imports}
|
||||
% endif
|
@ -9,10 +9,10 @@ Create Date: 2024-02-23 16:15:07.115641
|
||||
from uuid import UUID
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy import orm
|
||||
|
||||
import mealie.db.migration_types
|
||||
from alembic import op
|
||||
from mealie.core.root_logger import get_logger
|
||||
|
||||
logger = get_logger()
|
@ -12,10 +12,10 @@ from typing import Any
|
||||
from uuid import uuid4
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy import orm
|
||||
|
||||
import mealie.db.migration_types
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "d7c6efd2de42"
|
@ -7,9 +7,9 @@ Create Date: 2024-04-07 01:05:20.816270
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
import mealie.db.migration_types
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "7788478a0338"
|
@ -7,9 +7,8 @@ Create Date: 2024-06-22 10:17:03.323966
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
|
||||
from alembic import op
|
||||
from sqlalchemy import orm
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "32d69327997b"
|
@ -12,11 +12,11 @@ from typing import Any
|
||||
from uuid import uuid4
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from slugify import slugify
|
||||
from sqlalchemy import orm
|
||||
|
||||
import mealie.db.migration_types
|
||||
from alembic import op
|
||||
from mealie.core.config import get_app_settings
|
||||
|
||||
# revision identifiers, used by Alembic.
|
@ -9,7 +9,6 @@ Create Date: 2024-09-02 21:39:49.210355
|
||||
from textwrap import dedent
|
||||
|
||||
import sqlalchemy as sa
|
||||
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
@ -7,9 +7,9 @@ Create Date: 2024-09-18 14:52:55.831540
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
import mealie.db.migration_types
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "1fe4bd37ccc8"
|
@ -7,7 +7,6 @@ Create Date: 2024-10-01 14:17:00.611398
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
@ -7,9 +7,9 @@ Create Date: 2024-10-08 21:17:31.601903
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy import orm
|
||||
|
||||
from alembic import op
|
||||
from mealie.db.models._model_utils import guid
|
||||
|
||||
# revision identifiers, used by Alembic.
|
@ -7,7 +7,6 @@ Create Date: 2024-10-20 09:47:46.844436
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
@ -7,9 +7,9 @@ Create Date: 2024-10-23 15:50:59.888793
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy import orm
|
||||
|
||||
from alembic import op
|
||||
from mealie.db.models._model_utils.guid import GUID
|
||||
from mealie.services.scraper.cleaner import clean_yield
|
||||
|
@ -3,11 +3,11 @@ from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
from time import sleep
|
||||
|
||||
from sqlalchemy import engine, orm, text
|
||||
|
||||
from alembic import command, config, script
|
||||
from alembic.config import Config
|
||||
from alembic.runtime import migration
|
||||
from sqlalchemy import engine, orm, text
|
||||
|
||||
from mealie.core import root_logger
|
||||
from mealie.core.config import get_app_settings
|
||||
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.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()
|
||||
|
||||
@ -101,7 +101,7 @@ def main():
|
||||
if max_retry == 0:
|
||||
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):
|
||||
raise Exception("Provided alembic config path doesn't exist")
|
||||
|
@ -3,25 +3,23 @@ import os
|
||||
import uuid
|
||||
from logging import Logger
|
||||
from os import path
|
||||
from pathlib import Path
|
||||
from textwrap import dedent
|
||||
from typing import Any
|
||||
|
||||
from alembic import command
|
||||
from alembic.config import Config
|
||||
from fastapi.encoders import jsonable_encoder
|
||||
from pydantic import BaseModel
|
||||
from sqlalchemy import Connection, ForeignKey, ForeignKeyConstraint, MetaData, Table, create_engine, insert, text
|
||||
from sqlalchemy.engine import base
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
from alembic import command
|
||||
from alembic.config import Config
|
||||
from mealie.db import init_db
|
||||
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.services._base_service import BaseService
|
||||
|
||||
PROJECT_DIR = Path(__file__).parent.parent.parent.parent
|
||||
|
||||
|
||||
class ForeignKeyDisabler:
|
||||
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_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):
|
||||
raise Exception("Provided alembic config path doesn't exist")
|
||||
|
||||
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)
|
||||
|
||||
del db_dump["alembic_version"]
|
||||
|
@ -158,8 +158,8 @@ select = [
|
||||
|
||||
[tool.ruff.lint.per-file-ignores]
|
||||
"__init__.py" = ["E402", "E501"]
|
||||
"alembic/versions/2022*" = ["E501"]
|
||||
"alembic/versions/2023*" = ["E501"]
|
||||
"mealie/alembic/versions/2022*" = ["E501", "I001"]
|
||||
"mealie/alembic/versions/2023*" = ["E501", "I001"]
|
||||
"dev/scripts/all_recipes_stress_test.py" = ["E501"]
|
||||
"ldap_provider.py" = ["UP032"]
|
||||
"tests/conftest.py" = ["E402"]
|
||||
|
@ -2,9 +2,9 @@ import importlib.util
|
||||
import pathlib
|
||||
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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user