Skip to content

Xen192/gorm-graphql-gin-template

Repository files navigation

gorm-graphql-gin-template

SETUP

Copy and Configure Values from .env.example to .env

1. Migration

  • Install Atlasgo for Migration

2. DB Setup

make docker-db

3. Package Get

go mod tidy

Running Project

make

Generating Schema

make gen-graph generates the resolvers and objects from graphql schemma


Migration

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.

Required Changes

  • change the db-schema.sql file to adjust the expected final state of the db.

Commands

  • 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

Playground

  • 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"

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published