3
0

add(all): migrations for tests, statik update

This commit is contained in:
Tit Petric
2018-11-24 19:50:07 +00:00
parent 556a61b914
commit 297ffda5ad
3 changed files with 29 additions and 10 deletions

View File

@@ -9,10 +9,11 @@ import (
"sort" "sort"
"strings" "strings"
_ "github.com/crusttech/crust/sam/db/mysql"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/rakyll/statik/fs"
"github.com/titpetric/factory" "github.com/titpetric/factory"
"github.com/titpetric/statik/fs"
"github.com/crusttech/crust/sam/db/mysql"
) )
func statements(contents []byte, err error) ([]string, error) { func statements(contents []byte, err error) ([]string, error) {
@@ -23,7 +24,7 @@ func statements(contents []byte, err error) ([]string, error) {
} }
func Migrate(db *factory.DB) error { func Migrate(db *factory.DB) error {
statikFS, err := fs.New() statikFS, err := fs.New(mysql.Data())
if err != nil { if err != nil {
return errors.Wrap(err, "Error creating statik filesystem") return errors.Wrap(err, "Error creating statik filesystem")
} }

View File

@@ -2,12 +2,17 @@ package repository
import ( import (
"fmt" "fmt"
"github.com/joho/godotenv" "log"
"github.com/namsral/flag"
"github.com/titpetric/factory"
"os" "os"
"runtime" "runtime"
"testing" "testing"
"github.com/joho/godotenv"
"github.com/namsral/flag"
"github.com/titpetric/factory"
samMigrate "github.com/crusttech/crust/sam/db"
systemMigrate "github.com/crusttech/crust/system/db"
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
@@ -29,7 +34,19 @@ func TestMain(m *testing.M) {
} }
factory.Database.Add("default", dsn) factory.Database.Add("default", dsn)
factory.Database.MustGet().Profiler = &factory.Database.ProfilerStdout
db := factory.Database.MustGet()
db.Profiler = &factory.Database.ProfilerStdout
// migrate database schema
if err := systemMigrate.Migrate(db); err != nil {
log.Printf("Error running migrations: %+v\n", err)
return
}
if err := samMigrate.Migrate(db); err != nil {
log.Printf("Error running migrations: %+v\n", err)
return
}
os.Exit(m.Run()) os.Exit(m.Run())
} }

View File

@@ -9,10 +9,11 @@ import (
"sort" "sort"
"strings" "strings"
_ "github.com/crusttech/crust/system/db/mysql"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/rakyll/statik/fs"
"github.com/titpetric/factory" "github.com/titpetric/factory"
"github.com/titpetric/statik/fs"
"github.com/crusttech/crust/system/db/mysql"
) )
func statements(contents []byte, err error) ([]string, error) { func statements(contents []byte, err error) ([]string, error) {
@@ -23,7 +24,7 @@ func statements(contents []byte, err error) ([]string, error) {
} }
func Migrate(db *factory.DB) error { func Migrate(db *factory.DB) error {
statikFS, err := fs.New() statikFS, err := fs.New(mysql.Data())
if err != nil { if err != nil {
return errors.Wrap(err, "Error creating statik filesystem") return errors.Wrap(err, "Error creating statik filesystem")
} }