> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/database-devops/setup-db-devops/using-custom-script-for-harness-database-devops.md).

# Using Custom Script for Harness Database DevOps

In certain Database DevOps workflows, users may prefer or require a **custom script** to retrieve and manage their Liquibase changelog rather than using a connector or direct integration.

This guide provides a comprehensive overview of how to use a custom script for Database DevOps, including the creation of a DB Schema, deployment of the schema, and the use of pipeline variables.

## Use case

This guide supports the following scenario:

* The customer maintains a Liquibase changelog in a remote repository (e.g., GitHub, JFrog). This is particularly useful when the changelog is stored in a repository for which Harness does not provide a native connector.
* They want to download and extract this changelog dynamically via a custom shell script.
* The script can reference **pipeline variables**, such as build versions or access tokens.

{% hint style="info" %}
Before proceeding, ensure you have set up a **Docker Registry Connector** to define the custom base image used in your pipeline. Follow the official [Harness documentation](https://6a994c14e7528334531dbe29--harness-developer.netlify.app/docs/platform/connectors/cloud-providers/ref-cloud-providers/docker-registry-connector-settings-reference) to configure this connector.
{% endhint %}

## Deploy using a custom script

By following these steps, you can effectively manage your database changes and streamline your DevOps processes.

### Create a DB schema

1. Under `Database DevOps` in the Harness UI, navigate to `DB Schema`.
2. Click on the `Add New DB Schema` button.&#x20;

<div align="right"><figure><img src="https://4089095456-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWwqb27iUU3gZvwGNroZp%2Fuploads%2FOJK8kCB8DY1hGvh6XDZV%2Fimage.png?alt=media&amp;token=2eeebbb6-590e-4730-8a41-b35dab841915" alt=""><figcaption></figcaption></figure></div>

* **Connect to Data Schema**: Connect via Harness Connector or use a custom script to connect to the database schema stored in a remote repository.
* **Schema Path**: The path to the schema file in the repository. This is where the custom scripts writes the changelog files that DB DevOps should use during pipeline execution.
* **Image**: The Docker image to be used for the custom script. This should be a base image that has the necessary tools and libraries installed to execute your script.
* **Shell**: The shell to be used for executing the script. This can be `bash`or `sh`which are supported by the Docker image.
* **Script**: The custom script that will be executed. This script should include the logic to download and extract the changelog file from the remote repository.&#x20;
* For example:

  ```
  curl -H 'Authorization: token <+secrets.getValue("github")>'
   -H 'Accept: application/vnd.github.v3.raw'
   -L https://api.github.com/repos/Sonichigo/mux-sql/contents/liquibase.yml?ref=main -o changelog.yml
  ```

{% hint style="info" %}
**INFO**

If your custom script requires variables or parameters, you can reference them using JEXL expressions. For example, you can reference file secrets securely by their ID. Go to [referencing file secrets](https://6a994c14e7528334531dbe29--harness-developer.netlify.app/docs/platform/secrets/add-file-secrets#reference-by-id) to use file secrets in your script. To learn how DB DevOps supports runtime secrets specifically, go to [Runtime Secrets](https://6a994c14e7528334531dbe29--harness-developer.netlify.app/docs/database-devops/use-database-devops/get-started/runtime-secrets) to configure runtime secrets for DB DevOps.
{% endhint %}

3. Click on the `Save` button.
4. The DB Schema will be created and you can see the details in the UI.
5. Select the `DB Schema` and Click on the `Add New DB Instance` button.&#x20;

<figure><img src="https://4089095456-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWwqb27iUU3gZvwGNroZp%2Fuploads%2FT0hXTlHFgyOI1PTbyIjt%2Fimage.png?alt=media&amp;token=1507b071-e415-4507-9879-dcce06338e21" alt=""><figcaption></figcaption></figure>

* **Name of DB Instance**: The name of the DB Instance. This is the name that will be used in the pipeline to refer to this DB Instance.
* **Tags (optional)**: Tags to be used for the DB Instance. This can be used to change which instances are shown on the migration state dashboard. If left blank, the tags will be automatically generated.
* **Connector**: The JDBC Connector to be used for the DB Instance. This is the connector that will be used to connect to the database instance.
* **Context**: The context is used to control which changelogs are deployed to which environments. This is useful when you have multiple environments (e.g., dev, test, prod) and you want to deploy different changelogs to each environment.

### Deployment pipeline

1. Under `Database DevOps` in the Harness UI, navigate to `Pipelines`.
2. Click on the `Create a Pipeline` button.
3. Click on the `Add Stage` button and select `custom stage`.
4. In the `Stage` section, create `Add Step Group` as the stage type.

{% hint style="info" %}
**NOTE**

Toggle on the "Enable container based execution".
{% endhint %}

5. In the `Step Group` section, select `Add Step` as the step type. Under "DB DevOps", select `Apply Schema` as the step type.&#x20;

<figure><img src="https://4089095456-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWwqb27iUU3gZvwGNroZp%2Fuploads%2Fxt2ZjIr30P52JrjF7baw%2Fimage.png?alt=media&amp;token=413f1dc8-09e1-4840-bf84-761b888f1ed7" alt=""><figcaption></figcaption></figure>

* **Select DB Schema**: The DB Schema we created earlier.
* **Select DB Instance**: The Name of the DB Instance, which was created earlier in our DB Schema.
* **Tags (optional)**: Tags to be used for the DB Instance. This can be used to identify the DB Instance in the pipeline. If left blank, the tags will be automatically generated.

6. Click on the `Apply Changes` button, and then click on the `Save` button.
7. The pipeline will be created and you can see the details in the UI.
8. Click on the `Run` button to run the pipeline.

#### Final result

{% tabs %}
{% tab title="Visual Overview" %}

<figure><img src="https://4089095456-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWwqb27iUU3gZvwGNroZp%2Fuploads%2F2qp2tw08Q58Hlnl6KOBd%2Fimage.png?alt=media&amp;token=f795331f-f73d-4e72-a666-83d6764c1d7c" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="YAML Overview" %}

```yaml
pipeline:
  name: custom-changelog-script
  identifier: customchangelogscript
  projectIdentifier: default_project
  orgIdentifier: default
  tags: {}
  stages:
    - stage:
        name: deploy
        identifier: deploy
        description: "Deploy DB Schema using Custom Script"
        type: Custom
        spec:
          execution:
            steps:
              - stepGroup:
                  name: apply schema
                  identifier: apply_schema
                  steps:
                    - step:
                        type: DBSchemaApply
                        name: DBSchemaApply_1
                        identifier: DBSchemaApply_1
                        spec:
                          connectorRef: dockerHarness
                          dbSchema: customscript
                          dbInstance: test3
                          tag: my-deployment
                        timeout: 10m
                  stepGroupInfra:
                    type: KubernetesDirect
                    spec:
                      connectorRef: db
            rollbackSteps: []
          serviceDependencies: []
        tags: {}
```

{% endtab %}
{% endtabs %}

That is it! You have successfully created a DB Schema and deployed it using a custom script. You can now use this pipeline to deploy your DB Schema to the database instance.

## Next steps

* Go to [Rollback automation](https://6a994c14e7528334531dbe29--harness-developer.netlify.app/docs/database-devops/use-database-devops/rollback-for-database-schemas) to configure automated rollback for failed deployments.
* Go to [Author DB Change](/database-devops/use-db-devops/create-database-updates/configure-llm-for-database-devops.md) to use LLM-powered change authoring.
* Go to the [Database DevOps Troubleshooting Guide](https://developer.harness.io/database-devops/troubleshooting-and-resources/troubleshooting-guide/troubleshooting) to resolve common setup and runtime errors.
