Skip to content

Instantly share code, notes, and snippets.

@kevin-ip
Last active January 23, 2023 17:28
Show Gist options
  • Save kevin-ip/66b1a8e90646034e19495b40cf7b8ed4 to your computer and use it in GitHub Desktop.
Save kevin-ip/66b1a8e90646034e19495b40cf7b8ed4 to your computer and use it in GitHub Desktop.
ariga/atlas

ariga/atlas POC

Setup

  • download all files to a directory
  • install altasgo
  • ./setup.sh
  • login to DB verifying setup
docker exec -it atlas-demo bash
psql 'postgres://root:asdf@localhost/example'
select * from users;
expecting to see the following:
 id | name
----+------
  1 | foo
  2 | bar
  3 | baz
(3 rows)
  • apply migration, which rename name to user_name
atlas schema apply -u "postgres://root:asdf@localhost:5432/example?sslmode=disable" --to file://schema.v2.hcl
  • verify DB
example=# select * from users;
 id | user_name
----+-----------
  1 |
  2 |
  3 |
(3 rows)
table "users" {
schema = schema.public
column "id" {
null = false
type = integer
}
column "user_name" {
null = true
type = character_varying(100)
}
primary_key {
columns = [column.id]
}
}
schema "public" {
}
#!/usr/bin/env bash
docker run --rm -d --name atlas-demo -p 5432:5432 -e POSTGRES_USER=root -e POSTGRES_PASSWORD=asdf -e POSTGRES_DB=example postgres:13-alpine
sleep 5
docker exec atlas-demo psql 'postgres://root:asdf@localhost/example' -c "CREATE table if not exists users(id int PRIMARY KEY, name varchar(100)); insert into users(id, name) values (1, 'foo'), (2, 'bar'), (3, 'baz');"
atlas schema inspect -u "postgres://root:asdf@localhost:5432/example?sslmode=disable" > schema.hcl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment