Update sqly to get the migration path from the env
This commit is contained in:
parent
a2adc4ccf5
commit
f0cf5f9b2e
7
Makefile
7
Makefile
@ -53,15 +53,14 @@ docker:
|
||||
$(DOCKER_COMPOSE) up -d
|
||||
sleep 4
|
||||
|
||||
migration-tool:
|
||||
go get -v github.com/mattes/migrate
|
||||
|
||||
migration-schema: docker migration-tool
|
||||
migration-schema: docker
|
||||
$(MIGRATION) -path $(MIGRATION_SCHEMA) up
|
||||
|
||||
migration-dev-data: docker migration-schema
|
||||
$(MIGRATION) -path $(MIGRATION_TEST_DATA) up
|
||||
|
||||
migration: migration-schema migration-dev-data
|
||||
|
||||
dev: docker migration watch
|
||||
|
||||
clean:
|
||||
|
@ -1,7 +1,7 @@
|
||||
package sqly
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -9,6 +9,15 @@ import (
|
||||
"github.com/mattes/migrate/migrate"
|
||||
)
|
||||
|
||||
var migrationPath string
|
||||
|
||||
func init() {
|
||||
migrationPath = os.Getenv("MIGRATION_PATH")
|
||||
if migrationPath == "" {
|
||||
migrationPath = "../../../sql/migration"
|
||||
}
|
||||
}
|
||||
|
||||
// BaseModel have to be embeded in all your struct which reflect a table
|
||||
type BaseModel struct {
|
||||
ID string
|
||||
@ -19,9 +28,8 @@ type BaseModel struct {
|
||||
// RunWithLastestMigration runs your test with database migration set to the lastest
|
||||
func RunWithLastestMigration(db *sqlx.DB, pgdsn string, t *testing.T, test func(db *sqlx.DB, t *testing.T)) {
|
||||
defer func() {
|
||||
allErrors, ok := migrate.DownSync(pgdsn, "../sql")
|
||||
allErrors, ok := migrate.DownSync(pgdsn, migrationPath)
|
||||
if !ok {
|
||||
fmt.Println("Oh no ...")
|
||||
for _, err := range allErrors {
|
||||
t.Log(err)
|
||||
t.Fatal("We get some errors when reset the database schema")
|
||||
@ -29,9 +37,8 @@ func RunWithLastestMigration(db *sqlx.DB, pgdsn string, t *testing.T, test func(
|
||||
}
|
||||
}()
|
||||
|
||||
allErrors, ok := migrate.UpSync(pgdsn, "../sql")
|
||||
allErrors, ok := migrate.UpSync(pgdsn, migrationPath)
|
||||
if !ok {
|
||||
fmt.Println("Oh no ...")
|
||||
for _, err := range allErrors {
|
||||
t.Log(err)
|
||||
t.Fatal("Impossible to run test we get some errors when initialize the database schema")
|
||||
|
Loading…
x
Reference in New Issue
Block a user