Copy and Configure Values from .env.example to .env
- Install Atlasgo for Migration
make docker-db
go mod tidy
make
make gen-graph
generates the resolvers and objects from graphql schemma
db/migration/db-schema.sql
represents the final db state schema, thus it represents the state that the app db is expected to be in.
- change the
db-schema.sql
file to adjust the expected final state of the db.
make migrate-gen
, this analyzes the previous migrated state and the targeted final state and creates the required alter migrations to reach the desired state.make migrate-dry
, to test the eligibility of the migration and if a plan can be formulated.make migrate-apply
, to apply the prepared migrations.make migrate
, to generate and apply the migrations at once.make gen-model
generates the gorm object from the migrated database
- Generating Diffs:
atlas migrate diff --dir "file://db/migration" --to "file://db/db-schema.sql" --dev-url "postgres://postgres:admin@localhost:4400/migration?sslmode=disable"
- Applying Migration:
atlas migrate apply --dir "file://db/migration" --url "postgres://postgres:admin@localhost:4400/test?sslmode=disable"
--dry-run
- Applying Schema:
atlas schema apply --to "file://db/db-schema.sql" --dev-url "postgres://postgres:admin@localhost:4400/migration?sslmode=disable" --url "postgres://postgres:admin@localhost:4400/test?sslmode=disable" --exclude "atlas_schema_revisions"
dry-run
- Linting Migration:
atlas migrate lint --dir "file://db/migration" --dev-url "postgres://postgres:admin@localhost:4400/migration?sslmode=disable" --latest 1
- New Migration:
atlas migrate new --dir "file://db/migration"
- Rehashing:
atlas migrate hash --dir "file://db/migration"
- Comparing Any Schema:
atlas schema diff --from "postgres://postgres:admin@localhost:4400/test?sslmode=disable" --to "postgres://postgres:admin@localhost:4400/postgres?sslmode=disable"
- Down Migration:
atlas schema apply --to "file://db/migration?version=20230423161817" --dev-url "postgres://postgres:admin@localhost:4400/migration?sslmode=disable" --url "postgres://postgres:admin@localhost:4400/test?sslmode=disable" --exclude "atlas_schema_revisions"
atlas migrate set 20230423161817 --dir "file://db/migration" --url "postgres://postgres:admin@localhost:4400/test?sslmode=disable"