schema

package module
v0.0.0-...-ce57706 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2017 License: MIT Imports: 4 Imported by: 1

README

schema

GoDoc

MySQL schema builders for migrations.

Install

go get github.com/altipla-consulting/schema

Contributing

You can make pull requests or create issues in GitHub. Any code you send should be formatted using gofmt.

License

MIT License

Documentation

Overview

Package schema helps to build the schema migrations of a MySQL database.

Index

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.

Directories

Path Synopsis
Package column contains schemas for the common columns you need to create using the schema package.
Package column contains schemas for the common columns you need to create using the schema package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL