A template repo for using Atlas.
macOS + Linux:
curl -sSf https://atlasgo.sh | sh
Homebrew:
brew install ariga/tap/atlas
Docker:
docker pull arigaio/atlas
Click here to read instructions for other platforms.
This repo comes with a bootstrapped Dockerfile to package the migrations as a container image.
Build the container image:
docker build -t atlas:local .
This repo comes with preconfigured atlas.hcl
that defines a local MySQL-based dev environment named "local" which
you can reference using the --env local
flag.
Modify the desired schema of your database schema.hcl
:
schema "app" {
}
table "users" {
schema = schema.app
column "id" {
type = int
}
column "user_name" {
type = varchar(255)
unique = true
}
column "email" {
type = varchar(255)
unique = true
}
+ column "bio" {
+ type = text
+ unique = true
+ }
primary_key {
columns = [column.id]
}
}
Automatically generate a migration file:
atlas migrate diff --env local
To learn more about defining database schemas in HCL, check out the SQL resource documentation.
Apply the migration directory to your database:
atlas migrate apply --env local -u "mysql://root:pass@database-url:3306/app"
Verify the latest migration file in the directory is safe to apply:
atlas migrate lint --env local --latest 1