jackc / tern

The SQL Fan's Migrator
MIT License
925 stars 68 forks source link

Tern 6 : making go-bindata possible #7

Closed hsyed closed 7 years ago

hsyed commented 7 years ago

The request below (includes #4 as well, my bad). refactors the migrations logic away from a fs view.

I haven't decided what the best way to implement this would be, maybe exposing the following interface from the migrate package makes sense:

type MigrationLoader interface {
  Load(name string, body []byte) error
  LoadShared(name string, body []byte) error
  // Don't know how I feel about these methods -- they would need to be available if this interface is  
  // exposed.
  Migrate() error
  MigrateTo(targetVersion uint32) error
}

go-bindata generates the following functions, we could have a LoadMigrations method take these as an argument (I will pursue this approach first):

// AssetDir returns the file names below a certain
// directory embedded in the file by go-bindata.
// For example if you run go-bindata on data/... and data contains the
// following hierarchy:
//     data/
//       foo.txt
//       img/
//         a.png
//         b.png
// then AssetDir("data") would return []string{"foo.txt", "img"}
// AssetDir("data/img") would return []string{"a.png", "b.png"}
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
// AssetDir("") will return []string{"data"}.
func AssetDir(name string) ([]string, error)

and

// MustAsset is like Asset but panics when Asset would return an error.
// It simplifies safe initialization of global variables.
func MustAsset(name string) []byte