Move definition of db into dbmanager
This commit is contained in:
parent
9f234bb007
commit
bf89172f8a
@ -1,4 +1,6 @@
|
||||
# Standard library imports
|
||||
import os
|
||||
import sys
|
||||
|
||||
# PyQt imports
|
||||
|
||||
@ -6,6 +8,7 @@
|
||||
from alchemical import Alchemical # type:ignore
|
||||
|
||||
# App imports
|
||||
from config import Config
|
||||
|
||||
|
||||
class DatabaseManager:
|
||||
@ -29,3 +32,12 @@ class DatabaseManager:
|
||||
if DatabaseManager.__instance is None:
|
||||
DatabaseManager(database_url, **kwargs)
|
||||
return DatabaseManager.__instance
|
||||
|
||||
|
||||
# Establish database connection
|
||||
DATABASE_URL = os.environ.get("DATABASE_URL")
|
||||
if DATABASE_URL is None:
|
||||
raise ValueError("DATABASE_URL is undefined")
|
||||
if "unittest" in sys.modules and "sqlite" not in DATABASE_URL:
|
||||
raise ValueError("Unit tests running on non-Sqlite database")
|
||||
db = DatabaseManager.get_instance(DATABASE_URL, engine_options=Config.ENGINE_OPTIONS).db
|
||||
|
||||
@ -29,9 +29,9 @@ from classes import (
|
||||
TrackDTO,
|
||||
)
|
||||
from config import Config
|
||||
from dbmanager import db
|
||||
from log import log, log_call
|
||||
from models import (
|
||||
db,
|
||||
NoteColours,
|
||||
Playdates,
|
||||
PlaylistRows,
|
||||
|
||||
@ -34,14 +34,6 @@ import dbtables
|
||||
from log import log
|
||||
|
||||
|
||||
# Establish database connection
|
||||
DATABASE_URL = os.environ.get("DATABASE_URL")
|
||||
if DATABASE_URL is None:
|
||||
raise ValueError("DATABASE_URL is undefined")
|
||||
if "unittest" in sys.modules and "sqlite" not in DATABASE_URL:
|
||||
raise ValueError("Unit tests running on non-Sqlite database")
|
||||
db = DatabaseManager.get_instance(DATABASE_URL, engine_options=Config.ENGINE_OPTIONS).db
|
||||
|
||||
# Configure the cache region
|
||||
cache_region = make_region().configure(
|
||||
'dogpile.cache.memory', # Use in-memory caching for now (switch to Redis if needed)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user