示例#1
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):
        load_env("api")
        db_register(make_db_url())
        downgrade(self.migration_dir)
示例#2
0
class AlembicCurrent(BaseCommand):
    name = "alembic-current"
    aliases = ["al-current"]
    description = "run alembic current"
    migration_dir = join(db_dir("alembic"), "api")

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

    async def run(self):
        load_env("api")
        db_register(make_db_url())
        current(self.migration_dir)
示例#3
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):
        env = self.option("env")
        self.load_env(f"api.{env}")
        db_register(make_db_url())
        stamp(self.migration_dir)
示例#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
示例#5
0
 def run(self):
     load_env("db")
     db_register(make_db_url())
     downgrade(join(db_dir("alembic"), "api"))
示例#6
0
from os import walk
from os.path import join
from importlib import import_module
from bountydns.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"bountydns.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):
    if key in aliases:
        return aliases[key]
    return factories[key]
示例#7
0
from os import walk
from os.path import join
from importlib import import_module
from bountydns.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"bountydns.db.models.{base_name}"
            module = import_module(module_path, class_name)
            model = getattr(module, class_name)
            if model not in models:
                models.append(model)
示例#8
0
 def run(self):
     load_env("db")
     db_register(make_db_url())
     current(join(db_dir("alembic"), "api"))
示例#9
0
 def run(self):
     load_env("db")
     db_register(make_db_url())
     initialize(join(db_dir("alembic"), "api"))