Documentation ¶
Overview ¶
Package schema helps to build the schema migrations of a MySQL database.
Index ¶
- type Column
- type Connection
- func (conn *Connection) AddColumn(tableName string, col Column) error
- func (conn *Connection) AddUnique(tableName, indexName string, columnNames []string) error
- func (conn *Connection) AlterColumn(tableName, columnName, columnType string) error
- func (conn *Connection) AssignPrimaryKey(tableName string, columnNames []string) error
- func (conn *Connection) CreateTable(name string, columns []Column) error
- func (conn *Connection) CreateTableIfNotExists(name string, columns []Column) error
- func (conn *Connection) DropColumn(tableName, columnName string) error
- func (conn *Connection) DropPrimaryKey(name string) error
- func (conn *Connection) DropTable(name string) error
- func (conn *Connection) DropUnique(tableName, indexName string) error
- func (conn *Connection) RenameColumn(tableName, oldColumnName, columnName, columnType string) error
- func (conn *Connection) RenameTable(oldName, name string) error
- func (conn *Connection) TableExists(name string) (bool, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Column ¶
type Column interface { // SQL generates the SQL needed to create the column. SQL() string }
Column it's the common interface between all type of columns.
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection to the DB.
func NewConnection ¶
func NewConnection(db *sql.DB) *Connection
NewConnection stores a connection to a DB to apply schema changes to it.
func NewTestConnection ¶
func NewTestConnection(db *sql.DB) *Connection
NewTestConnection stores a connection to a DB to apply schema changes to it. All tables created with this connection will reside in memory for tests.
func (*Connection) AddColumn ¶
func (conn *Connection) AddColumn(tableName string, col Column) error
AddColumn creates a new column in a table that already exists.
func (*Connection) AddUnique ¶
func (conn *Connection) AddUnique(tableName, indexName string, columnNames []string) error
AddUnique adds a new unique index to a column.
func (*Connection) AlterColumn ¶
func (conn *Connection) AlterColumn(tableName, columnName, columnType string) error
AlterColumn changes the properties of a column. It needs the current type of the column.
func (*Connection) AssignPrimaryKey ¶
func (conn *Connection) AssignPrimaryKey(tableName string, columnNames []string) error
AssignPrimaryKey sets the new primary key of the table. It should have been dropped before, or not exist previously.
func (*Connection) CreateTable ¶
func (conn *Connection) CreateTable(name string, columns []Column) error
CreateTable creates a new table.
func (*Connection) CreateTableIfNotExists ¶
func (conn *Connection) CreateTableIfNotExists(name string, columns []Column) error
CreateTableIfNotExists creates the table if it is not already present.
func (*Connection) DropColumn ¶
func (conn *Connection) DropColumn(tableName, columnName string) error
DropColumn removes a column from a table.
func (*Connection) DropPrimaryKey ¶
func (conn *Connection) DropPrimaryKey(name string) error
DropPrimaryKey removes the primary key from a table (not the column, only the index).
func (*Connection) DropTable ¶
func (conn *Connection) DropTable(name string) error
DropTable drops a table.
func (*Connection) DropUnique ¶
func (conn *Connection) DropUnique(tableName, indexName string) error
DropUnique removes the unique index of a column.
func (*Connection) RenameColumn ¶
func (conn *Connection) RenameColumn(tableName, oldColumnName, columnName, columnType string) error
RenameColumn changes the name of a column. It needs the current type of the column. It is not recommended to change the type manually with that string (though it's possible).
func (*Connection) RenameTable ¶
func (conn *Connection) RenameTable(oldName, name string) error
RenameTable changes the name of the table to a new one.
func (*Connection) TableExists ¶
func (conn *Connection) TableExists(name string) (bool, error)
TableExists checks if the table already exists in the DB.