mealie/tests/utils/alembic_reader.py
Hayden 71f8c1066a
feat: server side search (#2112) (#2117)
* feat: server side search API (#2112)

* refactor repository_recipes filter building

* add food filter to recipe repository page_all

* fix query type annotations

* working search

* add tests and make sure title matches are ordered correctly

* remove instruction matching again

* fix formatting and small issues

* fix another linting error

* make search test no rely on actual words

* fix failing postgres compiled query

* revise incorrectly ordered migration

* automatically extract latest migration version

* test migration orderes

* run type generators

* new search function

* wip: new search page

* sortable field options

* fix virtual scroll issue

* fix search casing bug

* finalize search filters/sorts

* remove old composable

* fix type errors

---------

Co-authored-by: Sören <fleshgolem@gmx.net>
2023-02-11 21:26:10 -09:00

39 lines
986 B
Python

import importlib.util
import pathlib
from functools import lru_cache
from mealie.db.init_db import PROJECT_DIR
ALEMBIC_MIGRATIONS = PROJECT_DIR / "alembic" / "versions"
def import_file(module_name: str, file_path: pathlib.Path):
spec = importlib.util.spec_from_file_location(module_name, file_path)
if spec is None or spec.loader is None:
raise ImportError(f"Unable to import {module_name} from {file_path}")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
def latest_alembic_version() -> str:
latest = sorted(ALEMBIC_MIGRATIONS.glob("*.py"))[-1] # Assumes files are named in order
mod = import_file("alembic_version", latest)
revision = getattr(mod, "revision", None)
if revision is None:
raise Exception(f"Unable to find revision in {latest}")
return revision
@lru_cache(1)
def alembic_versions():
return [
{"version_num": latest_alembic_version()},
]