Environment by Branch in Harness Database DevOps
Using branch-based environments in Harness Database DevOps
Harness Database DevOps supports managing database changes using environment-specific branches. This approach allows you to maintain different configurations for development, staging, and production environments directly in your Git repository.
Why use environment branches in Harness Database DevOps?
Here are several reasons why teams opt for a branch-per-environment strategy:
Consistency with application deployment: If you are already managing app deployments using environment-specific branches, aligning your DB changes keeps both layers synchronized.
Environment-Specific Configurations: Maintain isolated configurations or schema changes for dev, staging, and production environments.
Controlled Progression: Promote and test changes in lower environments before merging them into production.
Audit Trail: Each branch maintains a commit history that improves traceability and accountability for schema changes.
What are the tradeoffs of branch per environment?
While beneficial, this approach introduces some complexity:
Increased Complexity: Managing multiple branches requires rigorous Git hygiene.
Potential for Drift: Without strict coordination, environments can diverge.
Merge Conflicts: More branches = more chances for conflict.
Overhead: Requires additional team effort to maintain branches and reviews.
Unintentional promotion of dev-only changes: If you are managing dev/staging-only changes (like test tables or mock data), they may unintentionally get merged into higher environments.
How to configure
Follow these steps to configure environment-based deployments in Harness Database DevOps:
1. Set up your Git branches
Create separate branches in your Git repo for each environment: development, staging, production, etc.
2. Define schema configuration per branch
Create a DB Schema definition for each environment branch.
Go to Database DevOps and click Add DB Schema.

3. Create a database instance
Create a separate database instance for each target environment.
Select the Database Schema and click Add DB Instances in Harness.
Create a new instance for each environment.
Attach the appropriate JDBC connector and context labels.

4. Configure a Git trigger
Set up a trigger for each branch so Harness deploys automatically when changes are merged.
Navigate to Pipeline Studio > Triggers.

Add a new Git trigger that listens for changes on each environment branch.
For example,
devtrigger watchesdevbranch merges.
Select the Git repository and specify the Event type (e.g.,
Push).
Click on Continue and Configure the conditions for the trigger:
Branch Name: Specify the branch to watch (e.g.,
dev,staging,prod).Changed Files: Optionally, specify file patterns to filter changes (e.g.,
schemas/*.sql).

Example Trigger Conditions Enter the Pipeline Inputs that the trigger will use:
Trigger Branch: This is the branch that the trigger will monitor.
Rollback Tag (Optional): Optionally, specify a tag to use for rollbacks.
Tag (Optional): Optionally, specify a tag to apply to the deployment.

Example Trigger Inputs
5. Design your pipeline
Build a pipeline that applies the correct schema for each environment branch.
In Pipelines, create a pipeline that includes a
DBSchemaApplystep.Set up the pipeline to:
Deploy using the associated schema and DB instance.
Apply only the changes in that branch.
Optionally include approvals, rollback, and verification steps.

6. Manage promotion between environments
Promote changes between environments using Git pull requests.
Use Git pull requests to promote changes between branches, for example
devtostagingorstagingtoprod.Harness will auto-detect the merged changes via the trigger and deploy accordingly.
Conclusion
Deploying by environment branches in Harness Database DevOps provides alignment with traditional application deployment strategies and gives teams clear separation of concerns. While it introduces more Git management overhead, it enables safer promotion paths and more isolated testing.
Ensure you manage drift carefully, use contexts to limit dev-only changes, and maintain strong PR discipline when promoting between branches.
Next steps
Go to Trunk-based development to compare the single-branch strategy and choose the right approach for your team.
Go to Create a pipeline in Database DevOps to build your first environment-based database pipeline.
Go to Automated rollback for database schemas to configure rollback strategies for failed deployments.
Last updated
Was this helpful?