-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trigger SQL migration from cmd/migrate
- Loading branch information
Showing
7 changed files
with
92 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
.PHONY: up down pull update clean install migrate test generate-sqlboiler generate-mocks psql run | ||
.PHONY: up down pull update clean migrate test generate-sqlboiler generate-mocks psql run | ||
|
||
up: | ||
docker compose up --detach postgres | ||
|
@@ -15,11 +15,8 @@ update: pull up | |
clean: | ||
docker compose down --remove-orphans --volumes | ||
|
||
install: | ||
go install github.com/rubenv/sql-migrate/[email protected] | ||
|
||
migrate: | ||
sql-migrate up | ||
go run ./cmd/migrate | ||
|
||
test: | ||
go test -cover ./... | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/abeltay/go-template/env" | ||
"github.com/abeltay/go-template/postgres" | ||
migrate "github.com/rubenv/sql-migrate" | ||
) | ||
|
||
func main() { | ||
options, err := env.LoadOSEnv() | ||
if err != nil { | ||
log.Fatalln("Error loading environment settings, exiting the program: ", err) | ||
} | ||
db, err := postgres.OpenDB(options) | ||
if err != nil { | ||
log.Fatalln("Database error: ", err) | ||
} | ||
defer db.Close() | ||
|
||
migrations := &migrate.FileMigrationSource{ | ||
Dir: "db/migrations", | ||
} | ||
n, err := migrate.Exec(db, "postgres", migrations, migrate.Up) | ||
if err != nil { | ||
log.Fatalln("Migrate error: ", err) | ||
} | ||
fmt.Printf("Applied %d migrations!\n", n) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters