arch golang-migrate

  1. Install the golang-migrate tool by running the following command in your terminal: go install -tags 'sqlite3' github.com/golang-migrate/migrate/v4/cmd/migrate@latest

  2. Initialize a new migration files directory by executing the following command: migrate create -ext sql -dir db/migration -seq <migration_name>

  3. Write your migration SQL in the newly created migration file.

  4. Apply the migrations to your database using the following command: migrate -database 'postgres://user:password@localhost:5432/database_name?sslmode=disable' -path ./db/migration up

  5. Roll back the last migration with the following command: migrate -database 'postgres://user:password@localhost:5432/database_name?sslmode=disable' -path ./db/migration down

  6. Check the status of your migrations with the command: migrate -database 'postgres://user:password@localhost:5432/database_name?sslmode=disable' -path ./db/migration version