You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by je...@apache.org on 2022/04/19 20:08:38 UTC
[airflow] branch main updated: Allow offline upgrade with no options (#23093)
This is an automated email from the ASF dual-hosted git repository.
jedcunningham pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new abaef54d54 Allow offline upgrade with no options (#23093)
abaef54d54 is described below
commit abaef54d54091ce1c59136247271fd68d4840e28
Author: Daniel Standish <15...@users.noreply.github.com>
AuthorDate: Tue Apr 19 13:08:31 2022 -0700
Allow offline upgrade with no options (#23093)
User should be able to do `airflow db upgrade --show-sql-only` when upgradeing to latest revision.
---
airflow/utils/db.py | 4 ++++
tests/utils/test_db.py | 11 +++++++++++
2 files changed, 15 insertions(+)
diff --git a/airflow/utils/db.py b/airflow/utils/db.py
index 98b7ae7fc2..03840dd6f5 100644
--- a/airflow/utils/db.py
+++ b/airflow/utils/db.py
@@ -1377,6 +1377,10 @@ def upgradedb(
if not from_revision:
from_revision = _get_current_revision(session)
+ if not to_revision:
+ script = _get_script_object()
+ to_revision = script.get_current_head()
+
if to_revision == from_revision:
print_happy_cat("No migrations to apply; nothing to do.")
return
diff --git a/tests/utils/test_db.py b/tests/utils/test_db.py
index 187253cc76..e2ea0168c3 100644
--- a/tests/utils/test_db.py
+++ b/tests/utils/test_db.py
@@ -137,6 +137,17 @@ class TestDb:
upgradedb(from_revision=from_revision, to_revision=to_revision, show_sql_only=True)
mock_alembic_upgrade.assert_called_once_with(mock.ANY, f"{from_revision}:{to_revision}", sql=True)
+ @mock.patch('airflow.utils.db._offline_migration')
+ @mock.patch('airflow.utils.db._get_current_revision')
+ def test_offline_upgrade_no_versions(self, mock_gcr, mock_om):
+ """Offline upgrade should work with no version / revision options."""
+ with mock.patch('airflow.utils.db.settings.engine.dialect') as dialect:
+ dialect.name = "postgresql" # offline migration not supported with postgres
+ mock_gcr.return_value = '90d1635d7b86'
+ upgradedb(from_revision=None, to_revision=None, show_sql_only=True)
+ actual = mock_om.call_args[0][2]
+ assert re.match(r'90d1635d7b86:[a-z0-9]+', actual) is not None
+
def test_offline_upgrade_fails_for_migration_less_than_2_0_0_head(self):
with mock.patch('airflow.utils.db.settings.engine.dialect'):
with pytest.raises(ValueError, match='Check that e1a11ece99cc is a valid revision'):