|
3 | 3 | import uuid
|
4 | 4 | from logging import Logger
|
5 | 5 | from os import path
|
6 |
| -from pathlib import Path |
7 | 6 | from textwrap import dedent
|
8 | 7 | from typing import Any
|
9 | 8 |
|
| 9 | +from alembic import command |
| 10 | +from alembic.config import Config |
10 | 11 | from fastapi.encoders import jsonable_encoder
|
11 | 12 | from pydantic import BaseModel
|
12 | 13 | from sqlalchemy import Connection, ForeignKey, ForeignKeyConstraint, MetaData, Table, create_engine, insert, text
|
13 | 14 | from sqlalchemy.engine import base
|
14 | 15 | from sqlalchemy.orm import sessionmaker
|
15 | 16 |
|
16 |
| -from alembic import command |
17 |
| -from alembic.config import Config |
18 | 17 | from mealie.db import init_db
|
19 | 18 | from mealie.db.fixes.fix_migration_data import fix_migration_data
|
| 19 | +from mealie.db.init_db import ALEMBIC_DIR |
20 | 20 | from mealie.db.models._model_utils.guid import GUID
|
21 | 21 | from mealie.services._base_service import BaseService
|
22 | 22 |
|
23 |
| -PROJECT_DIR = Path(__file__).parent.parent.parent.parent |
24 |
| - |
25 | 23 |
|
26 | 24 | class ForeignKeyDisabler:
|
27 | 25 | def __init__(self, connection: Connection, dialect_name: str, *, logger: Logger | None = None):
|
@@ -193,15 +191,12 @@ def restore(self, db_dump: dict) -> None:
|
193 | 191 | alembic_data = db_dump["alembic_version"]
|
194 | 192 | alembic_version = alembic_data[0]["version_num"]
|
195 | 193 |
|
196 |
| - alembic_cfg_path = os.getenv("ALEMBIC_CONFIG_FILE", default=str(PROJECT_DIR / "alembic.ini")) |
| 194 | + alembic_cfg_path = os.getenv("ALEMBIC_CONFIG_FILE", default=str(ALEMBIC_DIR / "alembic.ini")) |
197 | 195 |
|
198 | 196 | if not path.isfile(alembic_cfg_path):
|
199 | 197 | raise Exception("Provided alembic config path doesn't exist")
|
200 | 198 |
|
201 | 199 | alembic_cfg = Config(alembic_cfg_path)
|
202 |
| - # alembic's file resolver wants to use the "mealie" subdirectory when called from within the server package |
203 |
| - # Just override this to use the correct migrations path |
204 |
| - alembic_cfg.set_main_option("script_location", path.join(PROJECT_DIR, "alembic")) |
205 | 200 | command.upgrade(alembic_cfg, alembic_version)
|
206 | 201 |
|
207 | 202 | del db_dump["alembic_version"]
|
|
0 commit comments