mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-11-01 02:33:22 -04:00
* add support for setting db_url * fix tests * add db_username/password env variables * init db if super user doesn't exist * fix tests * fix tests * set SQLite default DB_URL * don't run tests on draft PRs * add lint/black tests * add test-all * spell check settings * black/flake8 * check format fail * new badges * rename workflow * fix formatting * remove white-space * test connection arguments for pg * format * add new values to template * format * remove old script * monkeypatch test db * working docker-compose for postgres * update docs * test pg workflow * format * add driver * install w/ poetry * setup container * change image * set database to localhost * update tests * set url * fix url path * disable cache * database init * bust cache * get by name Co-authored-by: hay-kot <hay-kot@pm.me>
20 lines
541 B
Python
20 lines
541 B
Python
import sqlalchemy as sa
|
|
from mealie.db.models.model_base import SqlAlchemyBase
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
|
|
def sql_global_init(db_url: str):
|
|
connect_args = {}
|
|
if "sqlite" in db_url:
|
|
connect_args["check_same_thread"] = False
|
|
|
|
engine = sa.create_engine(db_url, echo=False, connect_args=connect_args)
|
|
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
import mealie.db.models._all_models # noqa: F401
|
|
|
|
SqlAlchemyBase.metadata.create_all(engine)
|
|
|
|
return SessionLocal
|