Run migrations in 'online' mode. In this scenario we need to create an Engine and associate a connection with the context.
()
| 67 | |
| 68 | |
| 69 | def run_migrations_online(): |
| 70 | """Run migrations in 'online' mode. |
| 71 | |
| 72 | In this scenario we need to create an Engine |
| 73 | and associate a connection with the context. |
| 74 | |
| 75 | """ |
| 76 | configuration = config.get_section(config.config_ini_section) |
| 77 | configuration["sqlalchemy.url"] = get_url() |
| 78 | connectable = engine_from_config( |
| 79 | configuration, |
| 80 | prefix="sqlalchemy.", |
| 81 | poolclass=pool.NullPool, |
| 82 | ) |
| 83 | |
| 84 | with connectable.connect() as connection: |
| 85 | context.configure( |
| 86 | connection=connection, target_metadata=target_metadata, compare_type=True |
| 87 | ) |
| 88 | |
| 89 | with context.begin_transaction(): |
| 90 | context.run_migrations() |
| 91 | |
| 92 | |
| 93 | if context.is_offline_mode(): |