diff --git a/core/dbt/cli/main.py b/core/dbt/cli/main.py index 610163042c4..c30a616732e 100644 --- a/core/dbt/cli/main.py +++ b/core/dbt/cli/main.py @@ -110,6 +110,7 @@ def global_flags(func): @p.fail_fast @p.favor_state @p.indirect_selection + @p.keep_connections_alive @p.log_cache_events @p.log_file_max_bytes @p.log_format diff --git a/core/dbt/cli/params.py b/core/dbt/cli/params.py index 33f586248c5..690510b36c6 100644 --- a/core/dbt/cli/params.py +++ b/core/dbt/cli/params.py @@ -734,3 +734,11 @@ def _version_callback(ctx, _param, value): envvar="DBT_SHOW_RESOURCE_REPORT", hidden=True, ) + +keep_connections_alive = click.option( + "--keep-connections-alive/--no-keep-connections-alive", + envvar=None, + help="Experimental: Keep connections alive between dbt invocations. Useful when using dbt as an API.", + default=False, + is_flag=True, +) diff --git a/core/dbt/cli/requires.py b/core/dbt/cli/requires.py index 058b16cdfaa..bda9c7b096f 100644 --- a/core/dbt/cli/requires.py +++ b/core/dbt/cli/requires.py @@ -97,8 +97,8 @@ def wrapper(*args, **kwargs): if flags.RECORD_TIMING_INFO: ctx.with_resource(profiler(enable=True, outfile=flags.RECORD_TIMING_INFO)) - # Adapter management - ctx.with_resource(adapter_management()) + if not flags.KEEP_CONNECTIONS_ALIVE: + ctx.with_resource(adapter_management()) return func(*args, **kwargs)