Skip to content

Commit

Permalink
Prevent generation of empty revision files by alembic autogenerate (#…
Browse files Browse the repository at this point in the history
…39634)

* Prevent generation of empty revision files by alembic autogenerate

When the alembic autogenerate command is run, we should prevent it
from generating an mpty migration file with no upgrade operation.
We print on the command line that no changes were detected.

* fixup! Prevent generation of empty revision files by alembic autogenerate
  • Loading branch information
ephraimbuddy authored May 15, 2024
1 parent 6afc75f commit a7960a1
Show file tree
Hide file tree
Showing 3 changed files with 1,591 additions and 1,285 deletions.
9 changes: 9 additions & 0 deletions airflow/migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ def run_migrations_online():
and associate a connection with the context.
"""

def process_revision_directives(context, revision, directives):
if getattr(config.cmd_opts, "autogenerate", False):
script = directives[0]
if script.upgrade_ops and script.upgrade_ops.is_empty():
directives[:] = []
print("No change detected in ORM schema, skipping revision.")

with contextlib.ExitStack() as stack:
connection = config.attributes.get("connection", None)

Expand All @@ -108,6 +116,7 @@ def run_migrations_online():
compare_server_default=compare_server_default,
include_object=include_object,
render_as_batch=True,
process_revision_directives=process_revision_directives,
)

with context.begin_transaction():
Expand Down
2 changes: 1 addition & 1 deletion docs/apache-airflow/img/airflow_erd.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6ae5e112d66c30d36fbc27a608355ffd66853e34d7538223f69a71e2eba54b59
62c46e83c8c2a7051fa3d7388e06535bcd01fae4cb1d01b1096cc069a82a89f8
Loading

0 comments on commit a7960a1

Please sign in to comment.