diff --git a/changelog.md b/changelog.md index 511f2438..a32f0f0d 100644 --- a/changelog.md +++ b/changelog.md @@ -13,6 +13,7 @@ Bug Fixes * Respect `--logfile` when using `--execute` or standard input at the shell CLI. * Gracefully catch Paramiko parsing errors on `--list-ssh-config`. * Downgrade to Paramiko 3.5.1 to avoid crashing on DSA SSH keys. +* Offer schema name completions in `GRANT ... ON` forms. 1.44.2 (2026/01/13) diff --git a/mycli/packages/completion_engine.py b/mycli/packages/completion_engine.py index e6e7182c..8398b18c 100644 --- a/mycli/packages/completion_engine.py +++ b/mycli/packages/completion_engine.py @@ -338,8 +338,9 @@ def suggest_based_on_last_token( # The lists of 'aliases' could be empty if we're trying to complete # a GRANT query. eg: GRANT SELECT, INSERT ON - # In that case we just suggest all tables. + # In that case we just suggest all schemata and all tables. if not aliases: + suggest.append({"type": "database"}) suggest.append({"type": "table", "schema": parent}) return suggest diff --git a/test/test_smart_completion_public_schema_only.py b/test/test_smart_completion_public_schema_only.py index 7e213e70..a9f71410 100644 --- a/test/test_smart_completion_public_schema_only.py +++ b/test/test_smart_completion_public_schema_only.py @@ -462,6 +462,19 @@ def test_un_escaped_table_names(completer, complete_event): ) +# todo: the fixtures are insufficient; the database name should also appear in the result +def test_grant_on_suggets_tables_and_schemata(completer, complete_event): + text = "GRANT ALL ON " + position = len(text) + result = list(completer.get_completions(Document(text=text, cursor_position=position), complete_event)) + assert result == [ + Completion(text='users', start_position=0), + Completion(text='orders', start_position=0), + Completion(text='`select`', start_position=0), + Completion(text='`réveillé`', start_position=0), + ] + + def dummy_list_path(dir_name): dirs = { "/": [