2018-06-15 16:33:47 -05:00
|
|
|
package godoc_vfs_test
|
|
|
|
|
|
|
|
import (
|
2018-10-10 15:11:48 -07:00
|
|
|
"github.com/golang-migrate/migrate/v4"
|
|
|
|
"github.com/golang-migrate/migrate/v4/source/godoc_vfs"
|
2018-06-15 16:33:47 -05:00
|
|
|
"golang.org/x/tools/godoc/vfs/mapfs"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Example_mapfs() {
|
|
|
|
fs := mapfs.New(map[string]string{
|
|
|
|
"1_foobar.up.sql": "1 up",
|
|
|
|
"1_foobar.down.sql": "1 down",
|
|
|
|
"3_foobar.up.sql": "3 up",
|
|
|
|
"4_foobar.up.sql": "4 up",
|
|
|
|
"4_foobar.down.sql": "4 down",
|
|
|
|
"5_foobar.down.sql": "5 down",
|
|
|
|
"7_foobar.up.sql": "7 up",
|
|
|
|
"7_foobar.down.sql": "7 down",
|
|
|
|
})
|
|
|
|
|
|
|
|
d, err := godoc_vfs.WithInstance(fs, "")
|
|
|
|
if err != nil {
|
|
|
|
panic("bad migrations found!")
|
|
|
|
}
|
|
|
|
m, err := migrate.NewWithSourceInstance("godoc-vfs", d, "database://foobar")
|
|
|
|
if err != nil {
|
|
|
|
panic("error creating the migrations")
|
|
|
|
}
|
2019-04-27 01:47:16 +03:00
|
|
|
err = m.Up()
|
|
|
|
if err != nil {
|
|
|
|
panic("up failed")
|
|
|
|
}
|
2018-06-15 16:33:47 -05:00
|
|
|
}
|