# Deploy Code Changes On Merge

This template creates a Bolt schedule that automatically executes dbt™ model builds and deploys them to production when a new pull request is merged into the main branch. This type of Bolt schedule is commonly referred to as [Continuous Deployment](https://docs.paradime.io/app-help/documentation/bolt/ci-cd/continuous-deployment-with-bolt) or "CD".

{% hint style="success" %}

### Key Benefits

* Automatically deploy dbt™ model changes to production after merge
* Rebuild only modified models and their downstream dependencies
  {% endhint %}

{% hint style="info" %}

### Prerequisites

* [Scheduler Environment](https://docs.paradime.io/app-help/documentation/settings/connections/scheduler-environment) is connected to your data warehouse provider
* Existing Bolt Schedule that has executed "dbt run" successfully
  {% endhint %}

***

### How to Configure

Implementing the Continuous Deployment schedule requires a multi-step setup process. Follow these instructions carefully to ensure a successful configuration:

#### Part 1: Initial Schedule Setup

This initial setup lays the foundation for the Continuous Deployment schedule. It involves creating the schedule, configuring the Deferred Schedule and Last Run Type settings, and defining the commands and triggers.

1. From the Bolt home screen, select **+ New Schedule** and then **+ Create New Schedule**.
2. **Schedule Type**: Select *Deferred*, which enables manifest comparison between runs to identify the minimal set of models that need to be rebuilt.
3. **Name**: Provide a relevant name (e.g. "Continuous Deployment")
4. **Description (Optional)**: Describe the purpose of this schedule (e.g. "Deploy dbt models to production when a new pull request is merged")
5. **Deferred Schedule**: Initially, select an existing production schedule that has successfully executed the `dbt run` command. This allows the first Continuous Deployment run to have manifest files (AKA [artifacts](https://docs.paradime.io/app-help/documentation/managing-schedules/analyzing-run-details#logs-and-artifacts)) to compare against.
6. **Last Run Type**: Select *Last Successful Run* to ensure the schedule defers to a run that completed without any errors.
7. **Command Settings**: Add `dbt run --select state:modified+` to rebuild only the dbt models that have been modified since the last successful run.&#x20;

{% hint style="info" %}
If you've implemented[ Turbo CI](https://docs.paradime.io/app-help/documentation/bolt/ci-cd/turbo-ci), *don't include `dbt build`* as Turbo CI already handles model building and tests in the pull request workflow.
{% endhint %}

8. **Trigger Type**:
   * If on GitHub, use the *"On Merge"* trigger to automatically run the schedule when a pull request is merged.
   * If on other platforms ([GitLab](https://docs.paradime.io/app-help/documentation/bolt/ci-cd/continuous-deployment-with-bolt/using-gitlab-pipelines), [Azure](https://docs.paradime.io/app-help/documentation/bolt/ci-cd/continuous-deployment-with-bolt/using-azure-pipelines), [BitBucket](https://docs.paradime.io/app-help/documentation/bolt/ci-cd/continuous-deployment-with-bolt/using-bitbucket-pipelines)),use the *"On Merge"* trigger and call via the AP. Check our templates based on your Git provider [continuous-deployment-with-bolt](https://docs.paradime.io/app-help/documentation/bolt/ci-cd/continuous-deployment-with-bolt "mention")
9. [**Notification Settings**](https://docs.paradime.io/app-help/documentation/bolt/creating-schedules/notification-settings) (Optional): Configure success, failure, and SLA breach alerts via email, Slack, or MS Teams.
10. Click **"Deploy"** to publish the new Continuous Deployment schedule.

{% @arcade/embed flowId="6duNNuIhB4iEywRcI0BQ" url="<https://app.arcade.software/share/6duNNuIhB4iEywRcI0BQ>" %}

#### Part 2: Generate Initial Artifacts

The first run of the Continuous Deployment schedule is crucial, as it generates the initial manifest files (artifacts) that will be used for state comparison in subsequent runs. This part covers executing that initial run.

1. From the Bolt home screen, click on the newly created Continuous Deployment schedule.
2. Click **"Run"** to execute an initial run of the schedule and generate the manifest files (artifacts).
3. Verify the initial run was successful by checking the [run history](https://docs.paradime.io/app-help/documentation/managing-schedules/viewing-run-log-history#run-history)

{% hint style="info" %}
To view all generated [artifacts](https://docs.paradime.io/app-help/documentation/managing-schedules/analyzing-run-details#logs-and-artifacts), see documentation [analyzing individual run details](https://docs.paradime.io/app-help/documentation/managing-schedules/analyzing-run-details#artifacts).&#x20;
{% endhint %}

{% @arcade/embed flowId="G4HToy52Nd7Zad8s06GG" url="<https://app.arcade.software/share/G4HToy52Nd7Zad8s06GG>" %}

#### Part 3: Transition to Self-Sustaining Schedule

After the initial run, we can update the Deferred Schedule configuration to make the Continuous Deployment schedule self-sustaining. This allows it to compare each subsequent run against its own previous successful execution.

1. From the Bolt home screen, click on the Continuous Deployment schedule.
2. Click **"Edit"** to modify the schedule configuration.
3. Update the **Deferred Schedule** to "self" so the schedule can compare against its own previous successful run.&#x20;
4. Click **"Deploy"** to save the changes.

{% @arcade/embed flowId="TOm7oQtAJWB6RDSYBK3k" url="<https://app.arcade.software/share/TOm7oQtAJWB6RDSYBK3k>" %}

Now your Continuous Deployment schedule is set up and ready to automatically deploy dbt™ model changes to production after each merge. The schedule will intelligently rebuild only the necessary models, optimizing compute and providing immediate visibility into the deployment status.
