-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv.py
More file actions
38 lines (27 loc) · 1.18 KB
/
env.py
File metadata and controls
38 lines (27 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from logging.config import fileConfig
from alembic import context
from ellar.core import current_injector
from ellar.threading import run_as_sync
from ellar_sql.migrations import MultipleDatabaseAlembicEnvMigration
from ellar_sql.services import EllarSQLService
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name) # type:ignore[arg-type]
# logger = logging.getLogger("alembic.env")
# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.
@run_as_sync
async def main() -> None:
db_service: EllarSQLService = current_injector.get(EllarSQLService)
# initialize migration class
alembic_env_migration = MultipleDatabaseAlembicEnvMigration(db_service)
if context.is_offline_mode():
alembic_env_migration.run_migrations_offline(context) # type:ignore[arg-type]
else:
await alembic_env_migration.run_migrations_online(context) # type:ignore[arg-type]
main()