joncalhoun / migrate

MIT License
35 stars 4 forks source link

Add support for context.Context #2

Open diegobernardes opened 3 years ago

diegobernardes commented 3 years ago

I really like this project, it's a small and yet really good migration library, especially because it exposes a transaction that allows me to transform the data if needed.

In my opinion, this library just misses one important feature, support for context. It would be awesome to have a signature like this migrate.Migrate(ctx context.Context, sqlDB *sql.DB, dialect string)

joncalhoun commented 3 years ago

A few details might need ironed out for this to work. For instance, if this was the very first migration and the context cancels should the migrations table be rolled back as well?

I might also want to update the current SqlxMigration type to have functions like:

type SqlxMigration struct {
    ID       string
    Migrate  func(ctx context.Context, tx *sqlx.Tx) error
    Rollback func(ctx context.Context, tx *sqlx.Tx) error
}

Definitely doable. Might be a fun project to stream if I can find the time. Just need to find the time 😭