migrate

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2015 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Overview

migrate is the simple migrator, it has one option, which is whether it should remove other tables and fields that aren't mentioned in the schema.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alterer

type Alterer interface {
	HasTable(*schema.Table) (bool, error)
	CreateTable(*schema.Table) error
	RemoveTable(*schema.Table) error
	UpdateTable(*schema.Table) error
	RenameTable(*schema.Table, string) error

	HasColumn(*schema.Table, *schema.Column) (bool, error)
	CreateColumn(*schema.Table, *schema.Column) error
	ModifyColumn(*schema.Table, *schema.Column) error
	RenameColumn(*schema.Table, *schema.Column) error
	RemoveColumn(*schema.Table, *schema.Column) error

	HasIndex(*schema.Table, schema.Index) (bool, error)

	CreateIndex(*schema.Table, schema.Index) error
	RemoveIndex(*schema.Table, schema.Index) error
	// contains filtered or unexported methods
}

type Database

type Database struct {
	Alterer
	DB     *sql.DB
	Schema schema.Schema
	Translator
	NewTables      []*schema.Table
	ModifiedTables []*schema.Table
	DBMS           System
	Log            *log.Logger
}

func (*Database) ForeignKeysSatisfied

func (d *Database) ForeignKeysSatisfied(table *schema.Table) bool

func (*Database) Migrate

func (d *Database) Migrate() error

func (*Database) PareFields

func (d *Database) PareFields() error

func (*Database) SetAlterer

func (d *Database) SetAlterer()

func (*Database) UpToDate

func (d *Database) UpToDate() (bool, error)

type GenericDB

type GenericDB struct {
	DB                *sql.DB
	Specific          Alterer
	Convert           Translator
	Log               *log.Logger
	PrimaryKeyDef     string
	LengthableColumns map[string]bool
}

func (*GenericDB) CreateColumn

func (g *GenericDB) CreateColumn(table *schema.Table, col *schema.Column) error

func (*GenericDB) CreateIndex

func (g *GenericDB) CreateIndex(table *schema.Table, index schema.Index) error

func (*GenericDB) CreateTable

func (g *GenericDB) CreateTable(table *schema.Table) error

func (*GenericDB) HasColumn

func (g *GenericDB) HasColumn(table *schema.Table, col *schema.Column) (bool, error)

func (*GenericDB) HasIndex

func (g *GenericDB) HasIndex(table *schema.Table, index schema.Index) (bool, error)

func (*GenericDB) HasTable

func (g *GenericDB) HasTable(table *schema.Table) (bool, error)

func (*GenericDB) ModifyColumn

func (g *GenericDB) ModifyColumn(table *schema.Table, col *schema.Column) error

func (*GenericDB) RemoveColumn

func (g *GenericDB) RemoveColumn(table *schema.Table, col *schema.Column) error

func (*GenericDB) RemoveIndex

func (g *GenericDB) RemoveIndex(table *schema.Table, index schema.Index) error

func (*GenericDB) RemoveTable

func (g *GenericDB) RemoveTable(table *schema.Table) error

func (*GenericDB) RenameColumn

func (g *GenericDB) RenameColumn(table *schema.Table, col *schema.Column) error

func (*GenericDB) RenameTable

func (g *GenericDB) RenameTable(table *schema.Table, oldName string) error

func (*GenericDB) UpdateTable

func (g *GenericDB) UpdateTable(table *schema.Table) error

type MysqlDB

type MysqlDB struct {
	GenericDB
}

MysqlDB is ugh

func (*MysqlDB) CreateIndex

func (m *MysqlDB) CreateIndex(table *schema.Table, index schema.Index) error

func (*MysqlDB) CreateTable

func (m *MysqlDB) CreateTable(table *schema.Table) error

func (*MysqlDB) LengthableColumns

func (*MysqlDB) LengthableColumns() map[string]bool

func (*MysqlDB) String

func (*MysqlDB) String() string

func (*MysqlDB) UpdateTable

func (m *MysqlDB) UpdateTable(table *schema.Table) error

type PostgresDB

type PostgresDB struct {
	GenericDB
}

PostgresDB is pretty much the same as sqlite, except it can modify columns

func (*PostgresDB) CreateIndex

func (p *PostgresDB) CreateIndex(table *schema.Table, index schema.Index) error

func (*PostgresDB) CreateTable

func (p *PostgresDB) CreateTable(table *schema.Table) error

func (*PostgresDB) HasColumn

func (p *PostgresDB) HasColumn(table *schema.Table, col *schema.Column) (bool, error)

func (*PostgresDB) HasIndex

func (p *PostgresDB) HasIndex(table *schema.Table, index schema.Index) (bool, error)

func (PostgresDB) HasTable

func (p PostgresDB) HasTable(table *schema.Table) (bool, error)

func (*PostgresDB) LengthableColumns

func (p *PostgresDB) LengthableColumns() map[string]bool

func (*PostgresDB) String

func (*PostgresDB) String() string

func (*PostgresDB) UpdateTable

func (p *PostgresDB) UpdateTable(table *schema.Table) error

type SqliteDB

type SqliteDB struct {
	GenericDB
}

SqliteDB is the standard for the GenericDB, so it has no overridden functions

func (*SqliteDB) CreateIndex

func (s *SqliteDB) CreateIndex(table *schema.Table, index schema.Index) error

func (*SqliteDB) CreateTable

func (s *SqliteDB) CreateTable(table *schema.Table) error

func (*SqliteDB) HasColumn

func (s *SqliteDB) HasColumn(table *schema.Table, col *schema.Column) (bool, error)

func (*SqliteDB) HasIndex

func (s *SqliteDB) HasIndex(table *schema.Table, index schema.Index) (bool, error)

func (*SqliteDB) HasTable

func (s *SqliteDB) HasTable(table *schema.Table) (bool, error)

func (*SqliteDB) LengthableColumns

func (*SqliteDB) LengthableColumns() map[string]bool

func (*SqliteDB) String

func (*SqliteDB) String() string

func (*SqliteDB) UpdateTable

func (s *SqliteDB) UpdateTable(table *schema.Table) error

type System

type System int
const (
	Generic System = iota
	MySQL
	Sqlite
	Postgres
)

type Translator

type Translator interface {
	SQLTable(string) string
	SQLColumn(string, string) string
}

Jump to

Keyboard shortcuts

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