Only count bad refs when `moved` table exists (#23491)
authorDaniel Standish <15932138+dstandish@users.noreply.github.com>
Fri, 6 May 2022 12:42:22 +0000 (05:42 -0700)
committerGitHub <noreply@github.com>
Fri, 6 May 2022 12:42:22 +0000 (13:42 +0100)
commit6cc41abf6912fd2705b9ef7cf368c888c43c8af8
tree151537c501a11e3a21e9cbbb54fc3bd3573caea7
parent38860c1627ad88b6391af29e85828579ec2fdf76
Only count bad refs when `moved` table exists (#23491)

This keeps the logic to fail without upgrading when (A) there are bad rows and
(B) the "moved" table already exists. But we optimize so that we don't count
the bad rows unless the "moved" table is there. Previously we counted always,
but the first time a user attempts upgrade, the tables won't be there so
there's no point in counting.

Instead what we do is skip right to the CTAS, creating the _airflow_moved
tables. If there aren't any rows in the "moved" table, then we delete the table
immediately.

Also included here is a delete optimization, where we join to the moved table
instead of running the not exists query again.

Co-authored-by: Jed Cunningham <66968678+jedcunningham@users.noreply.github.com>
Co-authored-by: Ash Berlin-Taylor <ash@apache.org>
airflow/utils/db.py