refactor(backend): ♻️ cleanup HTTP service classes and remove database singleton (#687)

* refactor(backend): ♻️ cleanup duplicate code in http services

* refactor(backend): ♻️ refactor database away from singleton design

removed the database single and instead injected the session into a new Database class that is created during each request life-cycle. Now sessions no longer need to be passed into each method on the database

All tests pass, but there are likely some hidden breaking changes that were not discovered.

* fix venv

* disable venv cache

* fix install script

* bump poetry version

* postgres fixes

* revert install

* fix db initialization for postgres

* add postgres to docker

* refactor(backend): ♻️ cleanup unused and duplicate code in http services

* refactor(backend): remove sessions from arguments

* refactor(backend): ♻️ convert units and ingredients to use http service class

* test(backend):  add unit and food tests

* lint

* update tags

* re-enable cache

* fix missing fraction in db

* fix lint

Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
Hayden
2021-09-19 15:31:34 -08:00
committed by GitHub
parent c0e3f04c23
commit 476aefeeb0
68 changed files with 1131 additions and 1084 deletions

View File

@@ -7,7 +7,7 @@ import yaml
from pydantic import BaseModel
from mealie.core import root_logger
from mealie.db.database import db
from mealie.db.database import get_database
from mealie.schema.admin import MigrationImport
from mealie.schema.recipe import Recipe
from mealie.schema.user.user import PrivateUser
@@ -37,6 +37,10 @@ class MigrationBase(BaseModel):
user: PrivateUser
@property
def db(self):
return get_database(self.session)
@property
def temp_dir(self) -> TemporaryDirectory:
"""unpacks the migration_file into a temporary directory
@@ -66,7 +70,7 @@ class MigrationBase(BaseModel):
with open(yaml_file, "r") as f:
contents = f.read().split("---")
recipe_data = {}
for x, document in enumerate(contents):
for _, document in enumerate(contents):
# Check if None or Empty String
if document is None or document == "":
@@ -172,7 +176,7 @@ class MigrationBase(BaseModel):
exception = ""
status = False
try:
db.recipes.create(self.session, recipe.dict())
self.db.recipes.create(recipe.dict())
status = True
except Exception as inst: