sql-migrate icon indicating copy to clipboard operation
sql-migrate copied to clipboard

Ability to extend the sql-migrate#Migration

Open nvcnvn opened this issue 7 years ago • 0 comments

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{"....."},
		},
	},
}

nvcnvn avatar Feb 22 '17 07:02 nvcnvn