github.com/tufanbarisyildirim/pop@v4.13.1+incompatible/migration_info.go (about)

     1  package pop
     2  
     3  import "fmt"
     4  
     5  // Migration handles the data for a given database migration
     6  type Migration struct {
     7  	// Path to the migration (./migrations/123_create_widgets.up.sql)
     8  	Path string
     9  	// Version of the migration (123)
    10  	Version string
    11  	// Name of the migration (create_widgets)
    12  	Name string
    13  	// Direction of the migration (up)
    14  	Direction string
    15  	// Type of migration (sql)
    16  	Type string
    17  	// DB type (all|postgres|mysql...)
    18  	DBType string
    19  	// Runner function to run/execute the migration
    20  	Runner func(Migration, *Connection) error
    21  }
    22  
    23  // Run the migration. Returns an error if there is
    24  // no mf.Runner defined.
    25  func (mf Migration) Run(c *Connection) error {
    26  	if mf.Runner == nil {
    27  		return fmt.Errorf("no runner defined for %s", mf.Path)
    28  	}
    29  	return mf.Runner(mf, c)
    30  }
    31  
    32  // Migrations is a collection of Migration
    33  type Migrations []Migration
    34  
    35  func (mfs Migrations) Len() int {
    36  	return len(mfs)
    37  }
    38  
    39  func (mfs Migrations) Less(i, j int) bool {
    40  	return mfs[i].Version < mfs[j].Version
    41  }
    42  
    43  func (mfs Migrations) Swap(i, j int) {
    44  	mfs[i], mfs[j] = mfs[j], mfs[i]
    45  }