Esempio n. 1
0
class AlembicInit(BaseCommand):
    name = "alembic-init"
    aliases = ["al-init"]
    description = "run alembic init"
    migration_dir = join(db_dir("alembic"), "api")

    @classmethod
    def parser(cls, parser):
        return parser

    async def run(self):
        db_register(make_db_url())
        initialize(self.migration_dir)
Esempio n. 2
0
class AlembicStamp(BaseCommand):
    name = "alembic-stamp"
    aliases = ["al-stamp"]
    description = "run alembic stamp"
    migration_dir = join(db_dir("alembic"), "api")

    @classmethod
    def parser(cls, parser):
        return parser

    async def run(self):
        db_register(make_db_url())
        stamp(self.migration_dir)
Esempio n. 3
0
class AlembicDowngrade(BaseCommand):
    name = "alembic-downgrade"
    aliases = ["al-downgrade"]
    description = "run alembic downgrade"
    migration_dir = join(db_dir("alembic"), "api")

    @classmethod
    def parser(cls, parser):
        return parser

    async def run(self):
        env = self.option("env")
        db_register(make_db_url())
        downgrade(self.migration_dir)
Esempio n. 4
0
def engine(client, request):
    """Session-wide test database."""
    DB_PATH = get_resolved_db_path()

    if exists(DB_PATH):
        unlink(DB_PATH)

    migration_dir = join(db_dir("alembic"), "api")
    e = _engine()

    def teardown():
        _metadata().drop_all(bind=e)
        unlink(DB_PATH)

    upgrade(migration_dir)

    request.addfinalizer(teardown)

    return e
Esempio n. 5
0
from os import walk
from os.path import join
from importlib import import_module
from boucanpy.core.utils import db_dir, snake_to_title

factories = {}

factories_dir = db_dir("factories")
for directory_name, sub_directories, files in walk(factories_dir):
    for f in sorted(files):
        if not f.startswith("__") and not f.startswith("base"):
            base_name = f.split(".")[0]
            class_name = snake_to_title(base_name) + "Factory"
            module_path = f"boucanpy.db.factories.{base_name}"
            module = import_module(module_path, class_name)
            model = getattr(module, class_name)
            if class_name not in factories.keys():
                factories[class_name] = model

# aliases = [{f.alias: f} for f in factories if f.alias]


def factory(key, session=None):
    # if key in aliases:
    #     return aliases[key]
    f = factories[key]
    if session:
        f._meta.sqlalchemy_session = session
    return f
Esempio n. 6
0
from os import walk
from os.path import join
from importlib import import_module
from boucanpy.core.utils import db_dir, snake_to_title

models = {}

models_dir = db_dir("models")
for directory_name, sub_directories, files in walk(models_dir):
    for f in sorted(files):
        if not f.startswith("__") and not f.startswith("base"):
            base_name = f.split(".")[0]
            class_name = snake_to_title(base_name)
            module_path = f"boucanpy.db.models.{base_name}"
            module = import_module(module_path, class_name)
            model = getattr(module, class_name)
            if model not in models:
                models[class_name] = model


def model(key):
    # if key in aliases:
    #     return aliases[key]
    f = models[key]
    return f