jedcunningham commented on code in PR #46615:
URL: https://github.com/apache/airflow/pull/46615#discussion_r1949494588
##########
airflow/migrations/versions/0032_3_0_0_rename_execution_date_to_logical_date_and_nullable.py:
##########
@@ -60,7 +62,40 @@ def upgrade():
)
+def _move_offending_dagruns():
+ select_null_logical_date_query = "select * from dag_run where logical_date
is null"
+
+ conn = op.get_bind()
+ offline = context.is_offline_mode()
+
+ # If there are no offending rows, we can skip everything.
+ # This check is not possible in offline mode.
+ if not offline and
conn.execute(text(select_null_logical_date_query)).fetchone() is None:
+ return
+
+ # Copy offending data to a new table. This can be done directly in Postgres
+ # and SQLite with create-from-select; MySQL needs a special case.
+ offending_table_name =
f"{settings.AIRFLOW_MOVED_TABLE_PREFIX}__3_0_0__offending_dag_run"
+ if conn.dialect.name == "mysql":
+ op.execute(f"create table {offending_table_name} like dag_run")
+ op.execute(f"insert into {offending_table_name}
{select_null_logical_date_query}")
+ else:
+ op.execute(f"create table {offending_table_name} as
{select_null_logical_date_query}")
+
+ # In offline mode, since we can't check if there are offending rows, we may
+ # end up with an empty offending table. Leave a note for the user to drop
it
+ # themselves after review.
+ if offline:
+ op.execute(f"-- TODO: DAG runs unable to be downgraded are moved to
{offending_table_name}.")
+ op.execute(f"-- TODO: Table {offending_table_name} can be removed
after contained data are reviewd.")
Review Comment:
```suggestion
op.execute(f"-- TODO: Table {offending_table_name} can be removed
after contained data are reviewed.")
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]