|
@@ -31,6 +31,21 @@ target_metadata = models.Base.metadata
|
|
|
# ... etc.
|
|
|
|
|
|
|
|
|
+def exclude_tables_from_config(config_):
|
|
|
+ """Return list of tables to exclude"""
|
|
|
+ tables_ = config_.get("tables", None)
|
|
|
+ if tables_ is not None:
|
|
|
+ tables = tables_.split(",")
|
|
|
+ return tables
|
|
|
+
|
|
|
+exclude_tables = exclude_tables_from_config(config.get_section('alembic:exclude'))
|
|
|
+
|
|
|
+def include_object(object, name, type_, reflected, compare_to):
|
|
|
+ """Compare table names to excluded tables"""
|
|
|
+ if type_ == "table" and name in exclude_tables:
|
|
|
+ return False
|
|
|
+ return True
|
|
|
+
|
|
|
def run_migrations_offline():
|
|
|
"""Run migrations in 'offline' mode.
|
|
|
|
|
@@ -45,7 +60,10 @@ def run_migrations_offline():
|
|
|
"""
|
|
|
url = config.get_main_option("sqlalchemy.url")
|
|
|
context.configure(
|
|
|
- url=url, target_metadata=target_metadata, literal_binds=True
|
|
|
+ url=url,
|
|
|
+ target_metadata=target_metadata,
|
|
|
+ literal_binds=True,
|
|
|
+ include_object=include_object
|
|
|
)
|
|
|
|
|
|
with context.begin_transaction():
|
|
@@ -67,7 +85,9 @@ def run_migrations_online():
|
|
|
|
|
|
with connectable.connect() as connection:
|
|
|
context.configure(
|
|
|
- connection=connection, target_metadata=target_metadata
|
|
|
+ connection=connection,
|
|
|
+ target_metadata=target_metadata,
|
|
|
+ include_object=include_object
|
|
|
)
|
|
|
|
|
|
with context.begin_transaction():
|