Skip to content

Commit

Permalink
🧑‍💻 technologist (Makefile): Added some recipes that uses Goose to ma…
Browse files Browse the repository at this point in the history
…nage the database migrations
  • Loading branch information
kevinmarquesp committed Jul 20, 2024
1 parent d5becc7 commit 75d0a75
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ PROJECT_BIN = go_postr
GOTEST_BIN = gotestsum
TEST_TARGET = ./...

MIGRATIONS_TARGET = ./db/sqlite3/migrations
DATABASE_URL = ./tmp/database.sqlite3
DATABASE_PROVIDER = sqlite3

run: build
./$(TARGET)/$(PROJECT_BIN)
.PHONY: run
Expand All @@ -28,10 +32,31 @@ test-watch:
done
.PHONY: test-watch

depsget-all: depsget depsget-gose depsget-gotestsum
.PHONY: depsget-all

depsget:
$(GO_BIN) mod download
.PHONY: depsget

depsget-gose:
$(GO_BIN) install github.com/pressly/goose/v3/cmd/goose@latest
.PHONY: depsget-gotestsum

depsget-gotestsum:
$(GO_BIN) install gotest.tools/gotestsum@latest
.PHONY: depsget-gotestsum

migration-add:
@mkdir -vp $(MIGRATIONS_TARGET)
@read -rp "(read) File name: " file; \
GOOSE_DBSTRING=$(DATABASE_URL) goose -dir=$(MIGRATIONS_TARGET) $(DATABASE_PROVIDER) create "$$file" sql
.PHONY: migration-add

migration-up:
GOOSE_DBSTRING=$(DATABASE_URL) goose -dir=$(MIGRATIONS_TARGET) $(DATABASE_PROVIDER) up
.PHONY: migration-add

migration-reset:
GOOSE_DBSTRING=$(DATABASE_URL) goose -dir=$(MIGRATIONS_TARGET) $(DATABASE_PROVIDER) reset
.PHONY: migration-add

0 comments on commit 75d0a75

Please sign in to comment.