1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-12-18 09:35:25 +02:00
focalboard/server/services/store/sqlstore/migrate.go

54 lines
1.5 KiB
Go
Raw Normal View History

2020-10-16 22:27:16 +02:00
package sqlstore
import (
"fmt"
2020-10-16 22:27:16 +02:00
"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database"
"github.com/golang-migrate/migrate/v4/database/postgres"
"github.com/golang-migrate/migrate/v4/database/sqlite3"
_ "github.com/golang-migrate/migrate/v4/source/file"
bindata "github.com/golang-migrate/migrate/v4/source/go_bindata"
2020-10-16 22:27:16 +02:00
_ "github.com/lib/pq"
pgmigrations "github.com/mattermost/mattermost-octo-tasks/server/services/store/sqlstore/migrations/postgres"
"github.com/mattermost/mattermost-octo-tasks/server/services/store/sqlstore/migrations/sqlite"
2020-10-16 22:27:16 +02:00
)
func (s *SQLStore) Migrate() error {
fmt.Println("HOLA")
2020-10-16 22:27:16 +02:00
var driver database.Driver
var err error
var bresource *bindata.AssetSource
2020-10-16 22:27:16 +02:00
if s.dbType == "sqlite3" {
driver, err = sqlite3.WithInstance(s.db, &sqlite3.Config{})
fmt.Println(pgmigrations.AssetNames())
bresource = bindata.Resource(sqlite.AssetNames(),
func(name string) ([]byte, error) {
return sqlite.Asset(name)
})
2020-10-16 22:27:16 +02:00
}
if s.dbType == "postgres" {
driver, err = postgres.WithInstance(s.db, &postgres.Config{})
bresource = bindata.Resource(pgmigrations.AssetNames(),
func(name string) ([]byte, error) {
return pgmigrations.Asset(name)
})
}
d, err := bindata.WithInstance(bresource)
if err != nil {
return err
2020-10-16 22:27:16 +02:00
}
m, err := migrate.NewWithInstance("go-bindata", d, s.dbType, driver)
2020-10-16 22:27:16 +02:00
if err != nil {
return err
}
err = m.Up()
if err != nil && err != migrate.ErrNoChange {
return err
}
return nil
}