github.com/marinho/drone@v0.2.1-0.20140504195434-d3ba962e89a7/pkg/database/migrate/api.go (about)

     1  package migrate
     2  
     3  import (
     4  	"database/sql"
     5  )
     6  
     7  // Operation interface covers basic migration operations.
     8  // Implementation details is specific for each database,
     9  // see migrate/sqlite.go for implementation reference.
    10  type Operation interface {
    11  
    12  	// CreateTable may be used to create a table named `tableName`
    13  	// with its columns specification listed in `args` as an array of string
    14  	CreateTable(tableName string, args []string) (sql.Result, error)
    15  
    16  	// RenameTable simply rename table from `tableName` to `newName`
    17  	RenameTable(tableName, newName string) (sql.Result, error)
    18  
    19  	// DropTable drops table named `tableName`
    20  	DropTable(tableName string) (sql.Result, error)
    21  
    22  	// AddColumn adds single new column to `tableName`, columnSpec is
    23  	// a standard column definition (column name included) which may looks like this:
    24  	//
    25  	//     mg.AddColumn("example", "email VARCHAR(255) UNIQUE")
    26  	//
    27  	// it's equivalent to:
    28  	//
    29  	//     mg.AddColumn("example", mg.T.String("email", UNIQUE))
    30  	//
    31  	AddColumn(tableName, columnSpec string) (sql.Result, error)
    32  
    33  	// ChangeColumn may be used to change the type of a column
    34  	// `newType` should always specify the column's new type even
    35  	// if the type is not meant to be change. Eg.
    36  	//
    37  	//     mg.ChangeColumn("example", "name", "VARCHAR(255) UNIQUE")
    38  	//
    39  	ChangeColumn(tableName, columnName, newType string) (sql.Result, error)
    40  
    41  	// DropColumns drops a list of columns
    42  	DropColumns(tableName string, columnsToDrop ...string) (sql.Result, error)
    43  
    44  	// RenameColumns will rename columns listed in `columnChanges`
    45  	RenameColumns(tableName string, columnChanges map[string]string) (sql.Result, error)
    46  
    47  	// AddIndex adds index on `tableName` indexed by `columns`
    48  	AddIndex(tableName string, columns []string, flags ...string) (sql.Result, error)
    49  
    50  	// DropIndex drops index indexed by `columns` from `tableName`
    51  	DropIndex(tableName string, columns []string) (sql.Result, error)
    52  }
    53  
    54  // MigrationDriver drives migration script by injecting transaction object (*sql.Tx),
    55  // `Operation` implementation and column type helper.
    56  type MigrationDriver struct {
    57  	Operation
    58  	T  *columnType
    59  	Tx *sql.Tx
    60  }
    61  
    62  // DriverBuilder is a constructor for MigrationDriver
    63  type DriverBuilder func(tx *sql.Tx) *MigrationDriver