upd(all): migrations to goware/static, closes #106
This commit is contained in:
parent
d18f53f7c6
commit
a173071bbc
@ -9,9 +9,9 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/goware/statik/fs"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/titpetric/factory"
|
||||
"github.com/titpetric/statik/fs"
|
||||
|
||||
"github.com/crusttech/crust/crm/db/mysql"
|
||||
)
|
||||
@ -24,7 +24,7 @@ func statements(contents []byte, err error) ([]string, error) {
|
||||
}
|
||||
|
||||
func Migrate(db *factory.DB) error {
|
||||
statikFS, err := fs.New(mysql.Data())
|
||||
statikFS, err := fs.New(mysql.Asset)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Error creating statik filesystem")
|
||||
}
|
||||
|
||||
@ -1,12 +1,11 @@
|
||||
// +build migrations
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/titpetric/dockertest"
|
||||
"github.com/namsral/flag"
|
||||
"github.com/titpetric/factory"
|
||||
)
|
||||
|
||||
@ -16,32 +15,16 @@ func TestMigrations(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
args := []string{
|
||||
"--rm",
|
||||
"-e", "MYSQL_ROOT_PASSWORD=root",
|
||||
"-e", "MYSQL_DATABASE=test",
|
||||
}
|
||||
var dsn string
|
||||
|
||||
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(30*time.Second))
|
||||
defer cancel()
|
||||
flag.StringVar(&dsn, "db-dsn", "crust:crust@tcp(crust-db:3306)/crust?collation=utf8mb4_general_ci", "DSN for database connection")
|
||||
flag.Parse()
|
||||
|
||||
count := 0
|
||||
|
||||
mysql, err := dockertest.RunContainerContext(ctx, "titpetric/percona-xtrabackup", "3306", func(addr string) error {
|
||||
factory.Database.Add("default", "root:root@tcp("+addr+")/test?collation=utf8mb4_general_ci")
|
||||
log.Println(addr)
|
||||
_, err := factory.Database.Get()
|
||||
count++
|
||||
time.Sleep(time.Second)
|
||||
return err
|
||||
}, args...)
|
||||
defer mysql.Terminate() // Shutdown()
|
||||
if err != nil {
|
||||
t.Fatalf("Error starting mysql: %#v", err)
|
||||
}
|
||||
factory.Database.Add("default", dsn)
|
||||
factory.Database.Add("system", dsn)
|
||||
|
||||
db := factory.Database.MustGet()
|
||||
if err := Migrate(db); err != nil {
|
||||
t.Fatalf("Unexpected error: %#v", err)
|
||||
t.Fatalf("Unexpected error: %+v", err)
|
||||
}
|
||||
}
|
||||
|
||||
6
crm/db/mysql/static.go
Normal file
6
crm/db/mysql/static.go
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -9,9 +9,9 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/goware/statik/fs"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/titpetric/factory"
|
||||
"github.com/titpetric/statik/fs"
|
||||
|
||||
"github.com/crusttech/crust/messaging/db/mysql"
|
||||
)
|
||||
@ -24,7 +24,7 @@ func statements(contents []byte, err error) ([]string, error) {
|
||||
}
|
||||
|
||||
func Migrate(db *factory.DB) error {
|
||||
statikFS, err := fs.New(mysql.Data())
|
||||
statikFS, err := fs.New(mysql.Asset)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Error creating statik filesystem")
|
||||
}
|
||||
|
||||
@ -1,12 +1,11 @@
|
||||
// +build migrations
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/titpetric/dockertest"
|
||||
"github.com/namsral/flag"
|
||||
"github.com/titpetric/factory"
|
||||
)
|
||||
|
||||
@ -16,29 +15,13 @@ func TestMigrations(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
args := []string{
|
||||
"--rm",
|
||||
"-e", "MYSQL_ROOT_PASSWORD=root",
|
||||
"-e", "MYSQL_DATABASE=test",
|
||||
}
|
||||
var dsn string
|
||||
|
||||
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(30*time.Second))
|
||||
defer cancel()
|
||||
flag.StringVar(&dsn, "db-dsn", "crust:crust@tcp(crust-db:3306)/crust?collation=utf8mb4_general_ci", "DSN for database connection")
|
||||
flag.Parse()
|
||||
|
||||
count := 0
|
||||
|
||||
mysql, err := dockertest.RunContainerContext(ctx, "titpetric/percona-xtrabackup", "3306", func(addr string) error {
|
||||
factory.Database.Add("default", "root:root@tcp("+addr+")/test?collation=utf8mb4_general_ci")
|
||||
log.Println(addr)
|
||||
_, err := factory.Database.Get()
|
||||
count++
|
||||
time.Sleep(time.Second)
|
||||
return err
|
||||
}, args...)
|
||||
defer mysql.Terminate() // Shutdown()
|
||||
if err != nil {
|
||||
t.Fatalf("Error starting mysql: %#v", err)
|
||||
}
|
||||
factory.Database.Add("default", dsn)
|
||||
factory.Database.Add("system", dsn)
|
||||
|
||||
db := factory.Database.MustGet()
|
||||
if err := Migrate(db); err != nil {
|
||||
|
||||
6
messaging/db/mysql/static.go
Normal file
6
messaging/db/mysql/static.go
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -9,9 +9,9 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/goware/statik/fs"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/titpetric/factory"
|
||||
"github.com/titpetric/statik/fs"
|
||||
|
||||
"github.com/crusttech/crust/system/db/mysql"
|
||||
)
|
||||
@ -24,7 +24,7 @@ func statements(contents []byte, err error) ([]string, error) {
|
||||
}
|
||||
|
||||
func Migrate(db *factory.DB) error {
|
||||
statikFS, err := fs.New(mysql.Data())
|
||||
statikFS, err := fs.New(mysql.Asset)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Error creating statik filesystem")
|
||||
}
|
||||
|
||||
@ -1,12 +1,11 @@
|
||||
// +build migrations
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/titpetric/dockertest"
|
||||
"github.com/namsral/flag"
|
||||
"github.com/titpetric/factory"
|
||||
)
|
||||
|
||||
@ -16,29 +15,13 @@ func TestMigrations(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
args := []string{
|
||||
"--rm",
|
||||
"-e", "MYSQL_ROOT_PASSWORD=root",
|
||||
"-e", "MYSQL_DATABASE=test",
|
||||
}
|
||||
var dsn string
|
||||
|
||||
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(30*time.Second))
|
||||
defer cancel()
|
||||
flag.StringVar(&dsn, "db-dsn", "crust:crust@tcp(crust-db:3306)/crust?collation=utf8mb4_general_ci", "DSN for database connection")
|
||||
flag.Parse()
|
||||
|
||||
count := 0
|
||||
|
||||
mysql, err := dockertest.RunContainerContext(ctx, "titpetric/percona-xtrabackup", "3306", func(addr string) error {
|
||||
factory.Database.Add("default", "root:root@tcp("+addr+")/test?collation=utf8mb4_general_ci")
|
||||
log.Println(addr)
|
||||
_, err := factory.Database.Get()
|
||||
count++
|
||||
time.Sleep(time.Second)
|
||||
return err
|
||||
}, args...)
|
||||
defer mysql.Terminate() // Shutdown()
|
||||
if err != nil {
|
||||
t.Fatalf("Error starting mysql: %#v", err)
|
||||
}
|
||||
factory.Database.Add("default", dsn)
|
||||
factory.Database.Add("system", dsn)
|
||||
|
||||
db := factory.Database.MustGet()
|
||||
if err := Migrate(db); err != nil {
|
||||
|
||||
6
system/db/mysql/static.go
Normal file
6
system/db/mysql/static.go
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user