gormigrate icon indicating copy to clipboard operation
gormigrate copied to clipboard

callback functions after successful migration

Open karstenkoehler opened this issue 5 years ago • 1 comments

Hey, great work with this package so far. What I miss is a way to hook into a chain of migrations/rollbacks and execute some code after each successful migration. This could be used for example to report to current progress of the migrations. What I have in mind is something like extending the Options struct as follows. The methods would be called after each migration step.

type Options struct {
	// ...
	AfterMigration func(m *Migration)
	AfterRollback func(m *Migration)
}

If you are happy with that change, I can provide a PR for it.

karstenkoehler avatar Nov 03 '20 18:11 karstenkoehler

Hi @SchiffFlieger,

I think that having a single function for Before and After may be better:

type Options struct {
	// ...
	WhileMigrating func(m *Migration, yield func())
}
Options{
	// ...
	WhileMigrating: func(m *Migration, yield func()) {
		// Do something before

		yield()

		// Do something after
	}
}

I'm not sure about how useful this is, though. I'd like to hear more opinions before adding this to the lib.

andreynering avatar Jan 01 '21 20:01 andreynering