Skip to content

Commit 3ee6024

Browse files
committed
chore: minor tweak best practice
1 parent 8316b8f commit 3ee6024

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

content/blog/database-version-control-best-practice.md

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author: Adela
44
updated_at: 2025/04/06 16:40:00
55
feature_image: /content/blog/database-version-control-best-practice/cover.webp
66
tags: Industry
7-
description: "Database version control is the practice of managing and tracking changes to a database schema and its associated data over time. Why best practice matters? Mitigate risks, improve collaboration, and ensure data audibility."
7+
description: 'Database version control is the practice of managing and tracking changes to a database schema and its associated data over time. Why best practice matters? Mitigate risks, improve collaboration, and ensure data audibility.'
88
---
99

1010
This is a series of articles about database version control and database-as-code (GitOps)
@@ -25,8 +25,8 @@ Whether you prefer working with **scripts** along with GitOps or using a **GUI-b
2525

2626
Migration-based or State-based? This is the first major decision you need to make:
2727

28-
- **Migration-based**: You explicitly define step-by-step changes (e.g., add_user_table.sql). This works well with both script-based workflows (e.g., Flyway, Liquibase, Bytebase) and GUI tools like Bytebase.
29-
- **State-based**: You define the desired final state, and tools compute the diff. Ideal for GUI environments like SSMS, but also supported by schema-as-code tools like Atlas.
28+
- **Migration-based**: You explicitly define step-by-step changes (e.g., `add_user_table.sql`). This works well with both script-based workflows (e.g., Flyway, Liquibase) and GUI tools like Bytebase.
29+
- **State-based**: You define the desired final state, and tools compute the diff. The classic example is DACPAC for SQL Server.
3030

3131
You may dig deeper into the [Database Version Control, State-based or Migration-based?](/blog/database-version-control-state-based-vs-migration-based)
3232

@@ -42,7 +42,7 @@ One migration = one logical change. Each change should be tracked in its own mig
4242

4343
### 4. Automate Testing and Validation
4444

45-
For GUI-based approach, tools like Bytebase offer configurable SQL reviews and dry-run previews.
45+
For GUI-based approach, tools like Bytebase offer configurable SQL reviews and dry-run previews to suggest the estimated number of affected rows.
4646

4747
For Script-based approach, depending on your CI/CD tool, you can use GitHub Actions, GitLab CI, etc to integrate database testing tools to run SQL lint, syntax check and naming convention check.
4848

@@ -54,7 +54,7 @@ Add comments at the top of each file and link it to Jira/GitHub/GitLab issue for
5454

5555
For Script-based approach, you can enforce code review via GitHub/GitLab/Azure DevOps pull request.
5656

57-
GUI-based tools like Bytebase provides risk-based auto-match approval flow, for which you can customize risk level depending on operation and specify approval strategy.
57+
GUI-based tools like Bytebase provides risk-based auto-match approval flow, for which you can customize risk level depending on operation, target database and specify approval strategy.
5858

5959
### 7. Use a Clear Staging Strategy
6060

@@ -66,22 +66,37 @@ For GUI-based approach, Bytebase offers environment-based multi-stage workflow t
6666

6767
Provide a corresponding `xxxx_down.sql` or ensure backward compatible SQLs for each migration in script-based approach.
6868

69-
GUI tools like Bytebase provides build-in rollback feature.
69+
GUI tools like Bytebase provides built-in 1-click rollback feature.
7070

7171
### 9. Secure Sensitive Data
7272

73-
Don't hardcode secrets in your scripts, use environment variables or secrets management tools like Azure Key Vault, AWS Secrets Manager, etc in script-based approach. Use tool-specific secret injection features or managed credential stores in GUI-based approach.
73+
Don't hardcode secrets in your scripts, use environment variables or secrets management tools like HashiCorp Vault, AWS Secrets Manager, etc in script-based approach. Use tool-specific secret injection features or managed credential stores in GUI-based approach.
7474

7575
### 10. Track and Audit Every Change
7676

7777
For script-based approach, you can check schema versions, alert on failed migrations. For GUI-based tools like Bytebase, there is change history and audit logs for each migration.
7878

7979
## Summary
8080

81+
| Best Practice | Script-based Approach | GUI-based Approach |
82+
| ----------------------------------------- | ----------------------------------------------------------------------------------- | ------------------------------------------------------------------------ |
83+
| **Prefer Migration-based to State-based** | Define step-by-step changes in SQL files (e.g., Flyway, Liquibas, Bytebase) | Use Bytebase to manage migrations |
84+
| **Version All Artifacts** | Check in all database objects (tables, procedures, views, permissions) as SQL files | Create all changes through the tool's UI or API, never bypass the system |
85+
| **Practice Atomic Commit** | One migration file per logical change | One ticket per logical change |
86+
| **Automate Testing and Validation** | Integrate SQL linting, syntax checking via CI/CD pipelines | Bytebase provides built-in SQL review and dry-run |
87+
| **Document All Changes** | Add comments and link to issue trackers in migration files | Write detailed comments within the tool's interface |
88+
| **Enforce Approvals** | Use Git platform pull request reviews | Use Bytebase to configure risk-based approval workflows |
89+
| **Use a Clear Staging Strategy** | Use trunk-based development with feature branches | Utilize environment-based multi-stage workflows (dev → staging → prod) |
90+
| **Plan for Rollbacks** | Provide corresponding down migrations or backward compatible changes | Bytebase provides built-in 1-click rollback |
91+
| **Secure Sensitive Data** | Use environment variables or secrets management tools | Leverage tool-specific secret injection or managed credential stores |
92+
| **Track and Audit Every Change** | Monitor schema versions and alert on failed migrations | Bytebase provides built-in change history and audit logs |
93+
8194
Whether you're managing migrations through scripts along with GitOps or clicking through a UI, consistency is the key to safe database change management.
8295

8396
GUI tools accelerate onboarding, reduce human error, and often come with guardrails.
8497

8598
Script-based workflows offer greater flexibility, transparency, and Git-native operations.
8699

87-
The best practice? Pick one path that fits your team’s skill set, tooling, and stage of maturity. Just make sure every change is versioned, tested, reviewed, and traceable.
100+
The best practice? Pick one path that fits your team’s skill set, tooling, and stage of maturity. Just make sure every change is versioned, tested, reviewed, and traceable.
101+
102+
And remember, don't push on Friday.

0 commit comments

Comments
 (0)