# Database as Code

> Database as Code: schemas in version control, migrations as versioned scripts, deployments through CI/CD. State-based vs migration-based, and how to run it in production.

Source: https://www.bytebase.com/database-as-code/

---

## Versioned. Reviewed. Deployed. Audited.

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

## 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.

### 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 DAC.

## Read in order.

### What is Database Version Control?

Foundations: collaboration, history, deployment, GitOps integration. /blog/database-version-control

### State-based or migration-based?

The trade-offs that drive the IaC vs DAC divergence. /blog/database-version-control-state-based-vs-migration-based

### Database Version Control Best Practice

How teams actually run database-as-code in production. /blog/database-version-control-best-practice

## Get Started

- [Contact us](https://www.bytebase.com/contact-us/)
- [Start now (cloud)](https://console.bytebase.com)
