Atlas tools help developers manage their database schemas by applying modern DevOps principles. Contrary to existing tools, Atlas intelligently plans schema migrations for you, based on your desired state.
- MySQL
- MariaDB
- PostgresSQL
- SQLite
- TiDB
- CockroachDB
terraform {
required_providers {
atlas = {
source = "ariga/atlas"
version = "~> 0.1.0"
}
}
}
provider "atlas" {}
1. To create a schema for your database, first install atlas
:
brew install ariga/tap/atlas
Download:
curl -LO https://release.ariga.io/atlas/atlas-linux-amd64-latest
Install:
sudo install -o root -g root -m 0755 ./atlas-linux-amd64-latest /usr/local/bin/atlas
Download the latest release and move the atlas binary to a file location on your system PATH.
2. Then, inspect the schema of the database:
atlas schema inspect -d "mysql://root:pass@localhost:3306/example" > schema.hcl
3. Finally, configure the terraform resource to apply the state to your database:
data "atlas_schema" "my_schema" {
src = file("${path.module}/schema.hcl")
dev_db_url = "mysql://root:pass@localhost:3307/example"
}
resource "atlas_schema" "example_db" {
hcl = data.atlas_schema.my_schema.hcl
url = "mysql://root:pass@localhost:3306/example"
dev_db_url = "mysql://root:pass@localhost:3307/example"
}
For more advanced examples, check out the examples folder.