postgres

package
v4.14.6 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2021 License: MIT Imports: 13 Imported by: 0

README

postgres

postgres://user:password@host:port/dbname?query (postgresql:// works, too)

URL Query WithInstance Config Description Default value
x-migrations-table-has-schema MigrationsTableHasSchema Enable schema name support in x-migrations-table parameter false
x-migrations-table MigrationsTable Name of the migrations table, if x-migrations-table-has-schema is enabled then the first dot is treated as the schema and table name separator, for instance gomigrate.schema_migrations schema_migrations
x-statement-timeout StatementTimeout Abort any statement that takes more than the specified number of milliseconds 0
dbname DatabaseName The name of the database to connect to SELECT CURRENT_DATABASE() result
search_path This variable specifies the order in which schemas are searched when an object is referenced by a simple name with no schema specified. SHOW search_path result
user The user to sign in as
password The user's password
host The host to connect to. Values that start with / are for unix domain sockets localhost
port The port to bind to 5432
fallback_application_name An application_name to fall back to if one isn't provided.
connect_timeout Maximum wait for connection, in seconds. Zero or not specified means wait indefinitely.
sslcert Cert file location. The file must contain PEM encoded data.
sslkey Key file location. The file must contain PEM encoded data.
sslrootcert The location of the root certificate file. The file must contain PEM encoded data.
sslmode Whether or not to use SSL (disable|require|verify-ca|verify-full)

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>.

Multi-statement mode

In PostgreSQL running multiple SQL statements in one Exec executes them inside a transaction. Sometimes this behavior is not desirable because some statements can be only run outside of transaction (e.g. CREATE INDEX CONCURRENTLY). If you want to use CREATE INDEX CONCURRENTLY without activating multi-statement mode you have to put such statements in a separate migration files.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilConfig      = fmt.Errorf("no config")
	ErrNoDatabaseName = fmt.Errorf("no database name")
	ErrNoSchema       = fmt.Errorf("no schema")
	ErrDatabaseDirty  = fmt.Errorf("database is dirty")
)
View Source
var DefaultMigrationsTable = "schema_migrations"

Functions

func WithInstance

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

Types

type Config

type Config struct {
	MigrationsTableHasSchema bool
	MigrationsTable          string
	DatabaseName             string
	SchemaName               string
	StatementTimeout         time.Duration
}

type Postgres

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

func (*Postgres) Close

func (p *Postgres) Close() error

func (*Postgres) Drop

func (p *Postgres) Drop() (err error)

func (*Postgres) Open

func (p *Postgres) Open(url string) (database.Driver, error)

func (*Postgres) Run

func (p *Postgres) Run(migration io.Reader) error

func (*Postgres) SetVersion

func (p *Postgres) SetVersion(version int, dirty bool) error

func (*Postgres) Unlock

func (p *Postgres) Unlock() error

func (*Postgres) Version

func (p *Postgres) 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