rubenv / sql-migrate

SQL schema migration tool for Go.
MIT License
3.23k stars 280 forks source link

Ability to extend the sql-migrate#Migration #59

Open nvcnvn opened 7 years ago

nvcnvn commented 7 years ago

Currently the https://godoc.org/github.com/rubenv/sql-migrate#Migration has the Up, Down []string which I guess will be read and run by migrate.Exec. It would be nice if the Migration is an interface then we can do some update that need more than SQL script. For example:

type ComplexPwdGenMigration {
    DB
}
func (m *ComplexMigration) Up() []string {
// then something like:
// people := m.DB.GetAll()
// for each person in fo person.password = veryComplexPasswordGenerate(person.id) + m.DB.Save(person)
    return nil
}
//  and implement the rest method of 
migrations := &MixMigrationSource{
    Migrations: []Migrator{
        &migrate.Migration{
            Id:   "123",
            Up:   []string{"CREATE TABLE people (id int, password var)"},
            Down: []string{"DROP TABLE people"},
        },
        &ComplexPwdGenMigration,
        &AnotherComplexProcessMigration,
        &migrate.Migration{
            Id:   "123",
            Up:   []string{"...."},
            Down: []string{"....."},
        },
    },
}