sunank200 commented on code in PR #48403:
URL: https://github.com/apache/airflow/pull/48403#discussion_r2018620410


##########
airflow-core/src/airflow/cli/commands/config_command.py:
##########
@@ -704,3 +705,144 @@ def lint_config(args) -> None:
         console.print("\n[red]Please update your configuration file 
accordingly.[/red]")
     else:
         console.print("[green]No issues found in your airflow.cfg. It is ready 
for Airflow 3![/green]")
+
+
+@providers_configuration_loaded
+def update_config(args) -> None:
+    """
+    Update the airflow.cfg file to migrate configuration changes from Airflow 
2.x to Airflow 3.
+
+    This command scans the current configuration file for parameters that have 
been renamed,
+    removed, or had their default values changed in Airflow 3.0, and 
automatically updates
+    the configuration file.
+
+    CLI Arguments:
+        --section: str (optional)
+            Comma-separated list of configuration sections to update.
+            Example: --section core,database
+
+        --option: str (optional)
+            Comma-separated list of configuration options to update.
+            Example: --option sql_alchemy_conn,dag_concurrency
+
+        --ignore-section: str (optional)
+            Comma-separated list of configuration sections to ignore during 
update.
+            Example: --ignore-section webserver
+
+        --ignore-option: str (optional)
+            Comma-separated list of configuration options to ignore during 
update.
+            Example: --ignore-option check_slas
+
+        --dry-run: flag (optional)
+            Dry-run mode (print the changes without modifying airflow.cfg)
+            Example: --dry-run
+
+    Examples:
+        1. Update the entire configuration file:
+            airflow config update
+
+        2. Update only the 'core' and 'database' sections:
+            airflow config update --section core,database
+
+        3. Update only specific options:
+            airflow config update --option sql_alchemy_conn,dag_concurrency
+
+        4. Ignore updates for a specific section:
+            airflow config update --ignore-section webserver
+
+        5. Dry-run mode (print the changes without modifying airflow.cfg):
+            airflow config update --dry-run
+
+    :param args: The CLI arguments for updating configuration.
+    """
+    console = AirflowConsole()
+    changes_applied = []
+    modifications = ConfigModifications()
+
+    update_sections = args.section if args.section else None
+    update_options = args.option if args.option else None
+    ignore_sections = args.ignore_section if args.ignore_section else []
+    ignore_options = args.ignore_option if args.ignore_option else []
+
+    config_dict = conf.as_dict(
+        display_source=True,
+        include_env=True,
+        include_cmds=True,
+        include_secret=True,
+    )
+    for change in CONFIGS_CHANGES:
+        conf_section = change.config.section.lower()
+        conf_option = change.config.option.lower()
+        full_key = f"{conf_section}.{conf_option}"
+
+        if update_sections is not None and conf_section not in [s.lower() for 
s in update_sections]:
+            continue
+        if update_options is not None and full_key not in [opt.lower() for opt 
in update_options]:
+            continue
+        if conf_section in [s.lower() for s in ignore_sections] or full_key in 
[
+            opt.lower() for opt in ignore_options
+        ]:
+            continue
+
+        if conf_section not in config_dict or conf_option not in 
config_dict[conf_section]:
+            continue
+        value_data = config_dict[conf_section][conf_option]
+        if not (isinstance(value_data, tuple) and value_data[1] == 
"airflow.cfg"):
+            continue
+
+        current_value = value_data[0]
+
+        if change.default_change:
+            if str(current_value) != str(change.new_default):
+                modifications.add_default_update(conf_section, conf_option, 
str(change.new_default))
+                changes_applied.append(
+                    f"Updated default value of '{conf_section}/{conf_option}' 
from '{current_value}' to '{change.new_default}'."
+                )

Review Comment:
   changed it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to