"""Provide Router for db migrations.""" import os from contextlib import suppress from peewee_migrate import Router as PeeweeRouter from peewee_migrate.router import void __all__ = ["Router"] class Router(PeeweeRouter): """Like peewee_migrate.Router but supports multiple migrations dirs.""" # this is a slightly edited version from peewee_migrate.router.Router def __init__(self, database, migrations_dirs, **kwargs): super().__init__(database, migrate_dir=migrations_dirs[0], **kwargs) self.migrations_dirs = migrations_dirs @property def todo(self): """Scan migrations in file system.""" for migrate_dir in self.migrations_dirs: if not os.path.exists(migrate_dir): self.logger.warn( "Migration directory: %s does not exist.", migrate_dir ) os.makedirs(migrate_dir) migration_names = [] for migrate_dir in self.migrations_dirs: migration_names += sorted( f[: -len(".py")] for f in os.listdir(migrate_dir) if self.filemask.match(f) ) return migration_names def read(self, name): """Read migration from file.""" scope = {} for migrate_dir in self.migrations_dirs: with suppress(FileNotFoundError): with open(os.path.join(migrate_dir, name + ".py")) as f: code = compile( f.read(), "<string>", "exec", dont_inherit=True ) exec(code, scope) return scope.get("migrate", void), scope.get("rollback", void)
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
__pycache__ | Folder | 0755 |
|
|
api | Folder | 0755 |
|
|
application | Folder | 0755 |
|
|
contracts | Folder | 0755 |
|
|
feature_management | Folder | 0755 |
|
|
files | Folder | 0755 |
|
|
hooks | Folder | 0755 |
|
|
internals | Folder | 0755 |
|
|
migrations | Folder | 0755 |
|
|
model | Folder | 0755 |
|
|
mr_proper | Folder | 0755 |
|
|
myimunify | Folder | 0755 |
|
|
plugins | Folder | 0755 |
|
|
rpc_tools | Folder | 0755 |
|
|
simple_rpc | Folder | 0755 |
|
|
subsys | Folder | 0755 |
|
|
utils | Folder | 0755 |
|
|
__init__.py | File | 0 B | 0644 |
|
__main__.py | File | 43 B | 0644 |
|
_version.py | File | 82 B | 0644 |
|
defence360.py | File | 2.9 KB | 0644 |
|
migrate.py | File | 3.01 KB | 0644 |
|
router.py | File | 1.65 KB | 0644 |
|
run.py | File | 109 B | 0644 |
|
sentry.py | File | 2.85 KB | 0644 |
|