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)
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)
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)
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
def run(self): load_env("db") db_register(make_db_url()) downgrade(join(db_dir("alembic"), "api"))
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]
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)
def run(self): load_env("db") db_register(make_db_url()) current(join(db_dir("alembic"), "api"))
def run(self): load_env("db") db_register(make_db_url()) initialize(join(db_dir("alembic"), "api"))