31 lines
829 B
Python
31 lines
829 B
Python
import importlib
|
|
import logging
|
|
import os
|
|
from inspect import isclass
|
|
from pkgutil import iter_modules
|
|
from typing import final
|
|
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
from sqlalchemy.orm import DeclarativeBase
|
|
|
|
|
|
@final
|
|
class BaseModel(DeclarativeBase):
|
|
pass
|
|
|
|
|
|
db = SQLAlchemy(model_class=BaseModel)
|
|
|
|
|
|
def load_schema():
|
|
path = os.path.realpath(os.path.dirname(__file__) + os.sep + "schema")
|
|
for _, module_name, _ in iter_modules([path], f"{__name__}.schema."):
|
|
logging.getLogger("db").debug("Parsing module: %s" % module_name)
|
|
module = importlib.import_module(module_name)
|
|
|
|
for attribute_name in dir(module):
|
|
attribute = getattr(module, attribute_name)
|
|
|
|
if isclass(attribute) and issubclass(attribute, db.Table):
|
|
globals()[attribute_name] = attribute
|