mysql

package
v3.3.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2018 License: MIT Imports: 13 Imported by: 0

README

MySQL

mysql://user:password@tcp(host:port)/dbname?query

URL Query WithInstance Config Description
x-migrations-table MigrationsTable Name of the migrations table
dbname DatabaseName The name of the database to connect to
user The user to sign in as
password The user's password
host The host to connect to.
port The port to bind to.
x-tls-ca The location of the root certificate file.
x-tls-cert Cert file location.
x-tls-key Key file location.
x-tls-insecure-skip-verify Whether or not to use SSL (true|false)

Use with existing client

If you use the MySQL driver with existing database client, you must create the client with parameter multiStatements=true:

package main

import (
    "database/sql"
    
    _ "github.com/go-sql-driver/mysql"
    "github.com/golang-migrate/migrate"
    "github.com/golang-migrate/migrate/database/mysql"
    _ "github.com/golang-migrate/migrate/source/file"
)

func main() {
    db, _ := sql.Open("mysql", "user:password@tcp(host:port)/dbname?multiStatements=true")
    driver, _ := mysql.WithInstance(db, &mysql.Config{})
    m, _ := migrate.NewWithDatabaseInstance(
        "file:///migrations",
        "mysql", 
        driver,
    )
    
    m.Steps(2)
}

Upgrading from v1

  1. Write down the current migration version from schema_migrations
  2. DROP TABLE schema_migrations
  3. Wrap your existing migrations in transactions (BEGIN/COMMIT) if you use multiple statements within one migration.
  4. Download and install the latest migrate version.
  5. Force the current migration version with migrate force <current_version>.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDatabaseDirty  = fmt.Errorf("database is dirty")
	ErrNilConfig      = fmt.Errorf("no config")
	ErrNoDatabaseName = fmt.Errorf("no database name")
	ErrAppendPEM      = fmt.Errorf("failed to append PEM")
)
View Source
var DefaultMigrationsTable = "schema_migrations"

Functions

func WithInstance

func WithInstance(instance *sql.DB, config *Config) (database.Driver, error)

instance must have `multiStatements` set to true

Types

type Config

type Config struct {
	MigrationsTable string
	DatabaseName    string
}

type Mysql

type Mysql struct {
	// contains filtered or unexported fields
}

func (*Mysql) Close

func (m *Mysql) Close() error

func (*Mysql) Drop

func (m *Mysql) Drop() error

func (*Mysql) Lock

func (m *Mysql) Lock() error

func (*Mysql) Open

func (m *Mysql) Open(url string) (database.Driver, error)

func (*Mysql) Run

func (m *Mysql) Run(migration io.Reader) error

func (*Mysql) SetVersion

func (m *Mysql) SetVersion(version int, dirty bool) error

func (*Mysql) Unlock

func (m *Mysql) Unlock() error

func (*Mysql) Version

func (m *Mysql) Version() (version int, dirty bool, err error)

Jump to

Keyboard shortcuts

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