Coverage for slidge/db/alembic/env.py: 0%
22 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-11-07 05:11 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-11-07 05:11 +0000
1from alembic import context
3from slidge import global_config
4from slidge.db.meta import Base, get_engine
6config = context.config
8target_metadata = Base.metadata
11def run_migrations_offline() -> None:
12 """Run migrations in 'offline' mode.
14 This configures the context with just a URL
15 and not an Engine, though an Engine is acceptable
16 here as well. By skipping the Engine creation
17 we don't even need a DBAPI to be available.
19 Calls to context.execute() here emit the given string to the
20 script output.
22 """
23 url = config.get_main_option("sqlalchemy.url")
24 context.configure(
25 url=url,
26 target_metadata=target_metadata,
27 literal_binds=True,
28 dialect_opts={"paramstyle": "named"},
29 render_as_batch=True,
30 )
32 with context.begin_transaction():
33 context.run_migrations()
36def run_migrations_online() -> None:
37 """Run migrations in 'online' mode.
39 In this scenario we need to create an Engine
40 and associate a connection with the context.
42 """
43 try:
44 # in prod
45 connectable = get_engine(global_config.DB_URL)
46 except AttributeError:
47 # during dev, to generate migrations
48 connectable = get_engine("sqlite+pysqlite:///dev/slidge.sqlite")
50 with connectable.connect() as connection:
51 context.configure(
52 connection=connection,
53 target_metadata=target_metadata,
54 render_as_batch=True,
55 )
57 with context.begin_transaction():
58 context.run_migrations()
61if context.is_offline_mode():
62 run_migrations_offline()
63else:
64 run_migrations_online()