github.com/dannyzhou2015/migrate/v4@v4.15.2/source/iofs/example_test.go (about)

     1  //go:build go1.16
     2  // +build go1.16
     3  
     4  package iofs_test
     5  
     6  import (
     7  	"embed"
     8  	"log"
     9  
    10  	"github.com/dannyzhou2015/migrate/v4"
    11  	_ "github.com/dannyzhou2015/migrate/v4/database/postgres"
    12  	"github.com/dannyzhou2015/migrate/v4/source/iofs"
    13  )
    14  
    15  //go:embed testdata/migrations/*.sql
    16  var fs embed.FS
    17  
    18  func Example() {
    19  	d, err := iofs.New(fs, "testdata/migrations")
    20  	if err != nil {
    21  		log.Fatal(err)
    22  	}
    23  	m, err := migrate.NewWithSourceInstance("iofs", d, "postgres://postgres@localhost/postgres?sslmode=disable")
    24  	if err != nil {
    25  		log.Fatal(err)
    26  	}
    27  	err = m.Up()
    28  	if err != nil {
    29  		// ...
    30  	}
    31  	// ...
    32  }