Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More human friendly "show tables" output for db cleanup #38654

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions airflow/utils/db_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
10 changes: 5 additions & 5 deletions tests/utils/test_db_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,17 +395,17 @@ def test_confirm_drop_called_when_drop_archives_is_true_and_archive_exists(
@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(
Expand Down