cockroachdb

package module
v0.0.0-...-67a34a2 Latest Latest
Warning

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

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

README

CockroachDB Driver for Journey

Modeled after twrobel3's CockroachDB driver for mattes/migrate.

All db connection params are defined in the URL string, see this to know what's supported.

Migration script names should take the form <int_version>_<title>.up.sql and <int_version>_<title>.down.sql. I recommend using a timestamp (seconds since epoch) for <int_version> values.

By default, each migration script will run within a transaction, but you can opt-out of this by including the comment:

-- disable_ddl_transaction

as the first line in your script. Due to the nature of CockroachDB, disabling transactions may be necessary for scripts that need to alter the schema and insert reference/seed data.

Note that advisory locks are not supported in CockroachDB; therefore a manual lock table (with default name schema_lock) is used. This driver will acquire the lock and release it at the beginning and end of every migration script.

See db-journey/journey for details on using the journey CLI.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilConfig      = fmt.Errorf("no config")
	ErrNoDatabaseName = fmt.Errorf("no database name")
)
View Source
var DefaultLockTable = "schema_lock"
View Source
var DefaultMigrationsTable = "schema_migrations"

Functions

func FilterCustomQuery

func FilterCustomQuery(u *nurl.URL) *nurl.URL

FilterCustomQuery filters all query values starting with `x-`

func GenerateAdvisoryLockId

func GenerateAdvisoryLockId(databaseName string) (string, error)

func PopulateConfig

func PopulateConfig(driver *Driver, instance *sql.DB, config *Config) error

Types

type Config

type Config struct {
	MigrationsTable string
	LockTable       string
	ForceLock       bool
	DatabaseName    string
}

type Driver

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

func (*Driver) Close

func (driver *Driver) Close() error

Close closes the database handle.

func (*Driver) Execute

func (driver *Driver) Execute(statement string) error

Execute a SQL statement

func (*Driver) FilenameExtension

func (driver *Driver) FilenameExtension() string

FilenameExtension returns "sql".

func (*Driver) Initialize

func (driver *Driver) Initialize(url string) error

Initialize opens and verifies the database handle.

func (*Driver) Migrate

func (driver *Driver) Migrate(f file.File, pipe chan interface{})

Migrate performs the migration of any one file.

func (*Driver) SetDB

func (driver *Driver) SetDB(db *sql.DB)

SetDB replaces the current database handle.

func (*Driver) Version

func (driver *Driver) Version() (file.Version, error)

Version returns the current migration version.

func (*Driver) Versions

func (driver *Driver) Versions() (file.Versions, error)

Versions returns the list of applied migrations.

type Error

type Error struct {
	// Optional: the line number
	Line uint

	// Query is a query excerpt
	Query []byte

	// Err is a useful/helping error message for humans
	Err string

	// OrigErr is the underlying error
	OrigErr error
}

Error should be used for errors involving queries ran against the database

func (Error) Error

func (e Error) Error() string

Jump to

Keyboard shortcuts

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