Procházet zdrojové kódy

Ignore apscheduler jobs table

JoostSijm před 5 roky
rodič
revize
98d0066a5c
2 změnil soubory, kde provedl 25 přidání a 2 odebrání
  1. 3 0
      alembic.ini
  2. 22 2
      migrations/env.py

+ 3 - 0
alembic.ini

@@ -72,3 +72,6 @@ formatter = generic
 [formatter_generic]
 format = %(levelname)-5.5s [%(name)s] %(message)s
 datefmt = %H:%M:%S
+
+[alembic:exclude]
+tables = apscheduler_jobs

+ 22 - 2
migrations/env.py

@@ -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():