@@ -55,58 +55,56 @@ func (e ErrDirty) Error() string {
5555 return fmt .Sprintf ("Dirty database version %v. Fix and force version." , e .Version )
5656}
5757
58- // PostStepCallback is a callback function type that can be used to execute a
58+ // MigrationTask is a callback function type that can be used to execute a
5959// Golang based migration step after a SQL based migration step has been
6060// executed. The callback function receives the migration and the database
6161// driver as arguments.
62- type PostStepCallback func (migr * Migration , driver database.Driver ) error
62+ type MigrationTask func (migr * Migration , driver database.Driver ) error
6363
6464// options is a set of optional options that can be set when a Migrate instance
6565// is created.
6666type options struct {
67- // postStepCallbacks is a map of PostStepCallback functions that can be
68- // used to execute a Golang based migration step after a SQL based
69- // migration step has been executed. The key is the migration version
70- // and the value is the callback function that should be run _after_ the
71- // step was executed (but within the same database transaction).
72- postStepCallbacks map [uint ]PostStepCallback
67+ // tasks is a map of MigrationTask functions that can be used to execute
68+ // a Golang based migration step after a SQL based migration step ha
69+ // been executed. The key is the migration version and the value is the
70+ // callback function that should be run _after_ the step was executed
71+ // (but within the same database transaction).
72+ tasks map [uint ]MigrationTask
7373}
7474
7575// defaultOptions returns a new options struct with default values.
7676func defaultOptions () options {
7777 return options {
78- postStepCallbacks : make (map [uint ]PostStepCallback ),
78+ tasks : make (map [uint ]MigrationTask ),
7979 }
8080}
8181
8282// Option is a function that can be used to set options on a Migrate instance.
8383type Option func (* options )
8484
85- // WithPostStepCallbacks is an option that can be used to set a map of
86- // PostStepCallback functions that can be used to execute a Golang based
87- // migration step after a SQL based migration step has been executed. The key is
88- // the migration version and the value is the callback function that should be
89- // run _after_ the step was executed (but before the version is marked as
90- // cleanly executed). An error returned from the callback will cause the
91- // migration to fail and the step to be marked as dirty.
92- func WithPostStepCallbacks (
93- postStepCallbacks map [uint ]PostStepCallback ) Option {
94-
85+ // WithMigrationTasks is an option that can be used to set a map of
86+ // MigrationTask functions that can be used to execute a Golang based migration
87+ // step after a SQL based migration step has been executed. The key is the
88+ // migration version and the value is the task function that should be run
89+ // _after_ the step was executed (but before the version is marked as cleanly
90+ // executed). An error returned from the task will cause the migration to fail
91+ // and the step to be marked as dirty.
92+ func WithMigrationTasks (tasks map [uint ]MigrationTask ) Option {
9593 return func (o * options ) {
96- o .postStepCallbacks = postStepCallbacks
94+ o .tasks = tasks
9795 }
9896}
9997
100- // WithPostStepCallback is an option that can be used to set a PostStepCallback
98+ // WithMigrationTask is an option that can be used to set a MigrationTask
10199// function that can be used to execute a Golang based migration step after the
102100// SQL based migration step with the given version number has been executed. The
103- // callback is the function that should be run _after_ the step was executed
101+ // task is the function that should be run _after_ the step was executed
104102// (but before the version is marked as cleanly executed). An error returned
105- // from the callback will cause the migration to fail and the step to be marked
106- // as dirty.
107- func WithPostStepCallback (version uint , callback PostStepCallback ) Option {
103+ // from the task will cause the migration to fail and the step to be marked as
104+ // dirty.
105+ func WithMigrationTask (version uint , task MigrationTask ) Option {
108106 return func (o * options ) {
109- o .postStepCallbacks [version ] = callback
107+ o .tasks [version ] = task
110108 }
111109}
112110
@@ -818,22 +816,22 @@ func (m *Migrate) runMigrations(ret <-chan interface{}) error {
818816 return err
819817 }
820818
821- // If there is a post execution function for
822- // this migration, run it now.
823- cb , ok := m .opts .postStepCallbacks [migr .Version ]
819+ // If there is a task function for this
820+ // migration, run it now.
821+ cb , ok := m .opts .tasks [migr .Version ]
824822 if ok {
825- m .logVerbosePrintf ("Running post step " +
826- "callback for %v\n " , migr .LogString ())
823+ m .logVerbosePrintf ("Running migration " +
824+ "task for %v\n " , migr .LogString ())
827825
828826 err := cb (migr , m .databaseDrv )
829827 if err != nil {
830828 return fmt .Errorf ("failed to " +
831- "execute post " +
832- "step callback : %w" ,
829+ "execute migration " +
830+ "task : %w" ,
833831 err )
834832 }
835833
836- m .logVerbosePrintf ("Post step callback " +
834+ m .logVerbosePrintf ("Migration task " +
837835 "finished for %v\n " , migr .LogString ())
838836 }
839837 }
0 commit comments