This is an automated email from the ASF dual-hosted git repository. husseinawala 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 39b3eb2491 More human friendly "show tables" output for db cleanup (#38654) 39b3eb2491 is described below commit 39b3eb24917b87ce6bf5ba4f82599ed481b8c92a Author: Jed Cunningham <66968678+jedcunning...@users.noreply.github.com> AuthorDate: Mon Apr 1 17:28:16 2024 -0400 More human friendly "show tables" output for db cleanup (#38654) --- airflow/utils/db_cleanup.py | 10 ++++++---- tests/utils/test_db_cleanup.py | 10 +++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/airflow/utils/db_cleanup.py b/airflow/utils/db_cleanup.py index e6bbf2978e..e119c4228b 100644 --- a/airflow/utils/db_cleanup.py +++ b/airflow/utils/db_cleanup.py @@ -323,16 +323,18 @@ def _confirm_drop_archives(*, tables: list[str]): if len(tables) > 3: text_ = f"{len(tables)} archived tables prefixed with {ARCHIVE_TABLE_PREFIX}" else: - text_ = f"the following archived tables {tables}" + text_ = f"the following archived tables: {', '.join(tables)}" question = ( f"You have requested that we drop {text_}.\n" - f"This is irreversible. Consider backing up the tables first \n" + f"This is irreversible. Consider backing up the tables first.\n" ) print(question) if len(tables) > 3: - show_tables = ask_yesno("Show tables? (y/n): ") + show_tables = ask_yesno("Show tables that will be dropped? (y/n): ") if show_tables: - print(tables, "\n") + for table in tables: + print(f" {table}") + print("\n") answer = input("Enter 'drop archived tables' (without quotes) to proceed.\n").strip() if answer != "drop archived tables": raise SystemExit("User did not confirm; exiting.") diff --git a/tests/utils/test_db_cleanup.py b/tests/utils/test_db_cleanup.py index 4716870462..1f8e8f7ad2 100644 --- a/tests/utils/test_db_cleanup.py +++ b/tests/utils/test_db_cleanup.py @@ -395,17 +395,17 @@ class TestDBCleanup: @patch("airflow.utils.db_cleanup.ask_yesno") def test_confirm_drop_archives(self, mock_ask_yesno, tables): expected = ( - f"You have requested that we drop the following archived tables {tables}.\n" - "This is irreversible. Consider backing up the tables first" + f"You have requested that we drop the following archived tables: {', '.join(tables)}.\n" + "This is irreversible. Consider backing up the tables first." ) if len(tables) > 3: expected = ( f"You have requested that we drop {len(tables)} archived tables prefixed with " f"_airflow_deleted__.\n" - "This is irreversible. Consider backing up the tables first \n" - "\n" - f"{tables}" + "This is irreversible. Consider backing up the tables first.\n" ) + for table in tables: + expected += f"\n {table}" mock_ask_yesno.return_value = True with patch("sys.stdout", new=StringIO()) as fake_out, patch(