Skip to content

Latest commit

 

History

History
117 lines (81 loc) · 2.39 KB

atlasgo.md

File metadata and controls

117 lines (81 loc) · 2.39 KB

AtlasGo

https://github.com/ariga/atlas

Terraform for Database Schemas.

Install

https://atlasgo.io/getting-started

brew install ariga/tap/atlas

Inspect

https://atlasgo.io/declarative/inspect

HCL

atlas schema inspect -u "mysql://$USER:$PASSWORD@$HOST:3306/$DB" > schema.hcl

SQL

atlas schema inspect -u "mysql://$USER:$PASSWORD@$HOST:3306/$DB" --format '{{ sql . }}' > schema.sql

JSON

To be able to use jq on it:

atlas schema inspect -u "$URL" --format '{{ json . }}' | jq .

Visualize the Schema

By copying and pasting to:

https://gh.atlasgo.cloud/explore

Apply

https://atlasgo.io/declarative/apply

Edit the HCL or SQL file dumped from schema inspect, containing the HCL or SQL CREATE TABLE statements.

Then apply it to the URL of a database.

--to - a list of URLs to apply the desired state in the file to - can be a database URL, an HCL or SQL schema, or a migration directory:

atlas schema apply \
    -u "mysql://$USER:$PASSWORD@$HOST:3306/$DB" \
    --to file://schema.hcl

or

atlas schema apply \
    -u "mysql://$USER:$PASSWORD@$HOST:3306/$DB" \
    --to file://schema.sql \
    --dev-url "docker://mysql/8/$DB"  # url to a Dev database use to compute the diff
atlas schema inspect -u "mysql://$USER:$PASSWORD@$HOST:3306/$DB"
atlas migrate diff create_blog_posts \
    --dir "file://migrations" \
    --to "file://schema.hcl" \
    --dev-url "docker://mysql/8/$DB"  # url to a Dev database use to compute the diff

Compare 2 MySQL DBs:

atlas schema diff \
    --from "mysql://$USER:$PASSWORD@$HOST:3306/$DB1" \
    --to "mysql://$USER:$PASSWORD@$HOST:3306/$DB2"

The migrations/ directory will contain an SQL file and an atlas.sum file for integrity checking the migrations dir hasn't changed.

atlas migrate apply \
    --url "mysql://$USER:$PASSWORD@$HOST:3306/$DB" \
    --dir file://migrations
    --dry-run
atlas migrate apply \
    --url "postgres://$USER:$PASSWORD@$HOST:5432/$DB?search_path=public&sslmode=disable" \
    --dir file://migrations \
    --dry-run

Ported from private Knowledge Base page 2023+