Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for migrations from non filesystem sources #20

Open
hobeone opened this issue Jun 20, 2016 · 1 comment
Open

Support for migrations from non filesystem sources #20

hobeone opened this issue Jun 20, 2016 · 1 comment

Comments

@hobeone
Copy link

hobeone commented Jun 20, 2016

I'd like to add support for getting migrations from various sources. Either directly passed in as strings or built into the binary as an asset using something like go-bindata.

I think doing this the right way would substantially change gomigrate's API though. Here's what I was thinking:

NewMigrator(db, adapter, []Migrations)

  • This would change to just initializing the struct and wouldn't actually connect to the db
  • Since it's just initializing you wouldn't need a logger there and you could change the logger field to be a public field allowing users to set it to what the user wants after initialization

MigrationsFromDir("./path/to/migrations")

  • This would support the current behavior.

MigrationsFromAssets(Asset, AssetDir, "path")

  • This would allow consumption of migrations built with go-bindata

You could also just construct straight migrations in your go code and pass them in as an array.

Example use cases:

m := []Migrations{
  Migration{
    Id: 100,
    Up: `create table "foo" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" varchar(255) NOT NULL UNIQUE
);`,
   Down: `drop table "users";`,
}

migrator := NewMigrator(db, "sqlite3", m)
migrator.Logger = logrus.StandardLogger()
err := migrator.Migrate()
if err != nil {
  panic(err)
}
migrations, err := MigrationsFromDir(dirpath)
if err != nil {
  //handle error
}
migrator := NewMigrator(db, "sqlite3", migrations)
migrator.Migrate()

Since this would be a fairly substantial API change I wanted to see what you thought of the proposal before doing any work on it.

Thoughts?

@hobeone
Copy link
Author

hobeone commented Jun 22, 2016

I had time to hack on this and this is now supported in my fork:
https://github.com/hobeone/gomigrate

I got a little carried away and fixed some lint errors when they were highlighted in my editor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant