Skip to main content

Database as CodeVersioned. Reviewed. Deployed. Audited.

Database schemas live in version control. Schema changes flow through pull requests and CI/CD — the same path as application code.

Database as Code architecture

Two approaches. One source of truth.

State-based (declarative)

The full schema lives as one file in version control. Tools diff the file against the live database and reconcile. Single source of truth, simple to describe, harder for data migrations. The Infrastructure-as-Code default.

Migration-based (imperative)

Each schema change is a versioned migration script. Migrations execute in deterministic order. Reviewable per-change, replayable in CI/CD, mainstream in Database-as-Code.

Database as Code in Bytebase

Schema in code. Changes governed.

Bytebase connects GitHub, GitLab, Bitbucket, and Azure DevOps to the database. Schema changes flow as pull requests. Each change runs SQL review, lint, and policy enforcement before deployment. Migration history is captured automatically in both Bytebase and the VCS.

One workflow. Every database.

Database as Code questions

Common questions.

What is database as code?
Database as code is the practice of managing database schemas in version control, the same way application code is managed. Schema definitions and change scripts live in a Git repository. Changes go through pull requests, code review, CI checks, and automated deployment. The result: a versioned, reviewable, replayable history of every database change.
State-based or migration-based — which should I choose?
Migration-based is the mainstream choice for database as code. Each schema change is a versioned script applied in order — reviewable per change and replayable in CI/CD. State-based stores the full schema as one file and reconciles the database to match; this is how Infrastructure as Code (Terraform, Kubernetes) works, but it's harder to express data migrations. Many teams use a hybrid: migrations for changes, a state file as the source of truth.
Does database as code work with my existing CI/CD?
Yes. The same Git workflow that runs application CI/CD also runs database CI/CD. GitHub Actions, GitLab CI, Bitbucket Pipelines, Azure DevOps, Argo CD, and Flux can all execute schema migrations as part of the deployment pipeline — typically with a SQL review or lint step before applying.

Explore the standard for database development