Run migrations in 'online' mode. In this scenario we need to create an Engine and associate a connection with the context.
()
| 51 | |
| 52 | |
| 53 | def run_migrations_online(): |
| 54 | """Run migrations in 'online' mode. |
| 55 | |
| 56 | In this scenario we need to create an Engine |
| 57 | and associate a connection with the context. |
| 58 | |
| 59 | """ |
| 60 | connectable = engine_from_config( |
| 61 | |
| 62 | config.get_section(config.config_ini_section), |
| 63 | prefix="sqlalchemy.", |
| 64 | poolclass=pool.NullPool, |
| 65 | connect_args = {"options": "-c statement_timeout=270000 -c idle_in_transaction_session_timeout=270000"} # 4.5 mins timeout |
| 66 | ) |
| 67 | |
| 68 | with connectable.connect() as connection: |
| 69 | context.configure( |
| 70 | connection=connection, target_metadata=target_metadata |
| 71 | ) |
| 72 | |
| 73 | with context.begin_transaction(): |
| 74 | context.run_migrations() |
| 75 | |
| 76 | |
| 77 | if context.is_offline_mode(): |