singlestore

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: MIT Imports: 17 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
x-no-lock NoLock Set to true to skip GET_LOCK/RELEASE_LOCK statements. Useful for multi-master MySQL flavors. Only run migrations from one host when this is enabled.
x-statement-timeout StatementTimeout Abort any statement that takes more than the specified number of milliseconds, functionally similar to Server-side SELECT statement timeouts but enforced by the client. Available for all versions of MySQL, not just >=5.7.
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.
tls TLS / SSL encrypted connection parameter; see go-sql-driver. Use any name (e.g. migrate) if you want to use a custom TLS config (x-tls- queries).
x-tls-ca The location of the CA (certificate authority) file.
x-tls-cert The location of the client certificate file. Must be used with x-tls-key.
x-tls-key The location of the private key file. Must be used with x-tls-cert.
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/v4"
    "github.com/golang-migrate/migrate/v4/database/mysql"
    _ "github.com/golang-migrate/migrate/v4/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 (
	DefaultMigrationsTable = "schema_migrations"
	DefaultHistoryTable    = "schema_migrations_history"
)
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")
	ErrTLSCertKeyConfig = fmt.Errorf("To use TLS client authentication, both x-tls-cert and x-tls-key must not be empty")
)

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
	MigrationsHistoryTable       string
	MigrationsHistoryEnabled     bool
	DatabaseName                 string
	NoLock                       bool
	StatementTimeout             time.Duration
	ForceTransactionalMigrations bool
}

type Singlestore

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

func WithConnection

func WithConnection(ctx context.Context, conn *sql.Conn, config *Config) (*Singlestore, error)

connection instance must have `multiStatements` set to true

func (*Singlestore) Close

func (m *Singlestore) Close() error

func (*Singlestore) Drop

func (m *Singlestore) Drop() (err error)

func (*Singlestore) ListAppliedVersions

func (m *Singlestore) ListAppliedVersions() ([]int, error)

func (*Singlestore) Lock

func (m *Singlestore) Lock() error

func (*Singlestore) Open

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

func (*Singlestore) Run

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

func (*Singlestore) SetSourceDriver

func (m *Singlestore) SetSourceDriver(sourceDrv source.Driver) error

func (*Singlestore) SetVersion

func (m *Singlestore) SetVersion(version int, dirty bool, forced bool, knownDirection *source.Direction) (*source.Direction, error)

func (*Singlestore) Unlock

func (m *Singlestore) Unlock() error

func (*Singlestore) Version

func (m *Singlestore) 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