aboutsummaryrefslogtreecommitdiff
path: root/migrations/env.py
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2020-03-10 10:34:00 +0100
committerCédric Bonhomme <cedric@cedricbonhomme.org>2020-03-10 10:34:00 +0100
commit677304ba3ecbd204fa2726e6820de84ad09bd868 (patch)
treebd19fbf2f1a0cddad1980fe15cf4c228867c5d69 /migrations/env.py
parentUpdated README. (diff)
downloadnewspipe-677304ba3ecbd204fa2726e6820de84ad09bd868.tar.gz
newspipe-677304ba3ecbd204fa2726e6820de84ad09bd868.tar.bz2
newspipe-677304ba3ecbd204fa2726e6820de84ad09bd868.zip
Added a tiny portion of black magic.
Diffstat (limited to 'migrations/env.py')
-rw-r--r--migrations/env.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/migrations/env.py b/migrations/env.py
index 7215fefe..4f31b751 100644
--- a/migrations/env.py
+++ b/migrations/env.py
@@ -9,15 +9,18 @@ config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
-#fileConfig("./alembic.ini")
+# fileConfig("./alembic.ini")
# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
from flask import current_app
-config.set_main_option('sqlalchemy.url', current_app.config.get('SQLALCHEMY_DATABASE_URI'))
-target_metadata = current_app.extensions['migrate'].db.metadata
+
+config.set_main_option(
+ "sqlalchemy.url", current_app.config.get("SQLALCHEMY_DATABASE_URI")
+)
+target_metadata = current_app.extensions["migrate"].db.metadata
# other values from the config, defined by the needs of env.py,
@@ -25,6 +28,7 @@ target_metadata = current_app.extensions['migrate'].db.metadata
# my_important_option = config.get_main_option("my_important_option")
# ... etc.
+
def run_migrations_offline():
"""Run migrations in 'offline' mode.
@@ -43,6 +47,7 @@ def run_migrations_offline():
with context.begin_transaction():
context.run_migrations()
+
def run_migrations_online():
"""Run migrations in 'online' mode.
@@ -52,18 +57,17 @@ def run_migrations_online():
"""
connectable = engine_from_config(
config.get_section(config.config_ini_section),
- prefix='sqlalchemy.',
- poolclass=pool.NullPool)
+ prefix="sqlalchemy.",
+ poolclass=pool.NullPool,
+ )
with connectable.connect() as connection:
- context.configure(
- connection=connection,
- target_metadata=target_metadata
- )
+ context.configure(connection=connection, target_metadata=target_metadata)
with context.begin_transaction():
context.run_migrations()
+
if context.is_offline_mode():
run_migrations_offline()
else:
bgstack15