postgres

package
v0.10.4 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2022 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package postgres provides an implementation of the schema.driver interface for a PostgreSQL database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Postgres

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

Postgres is a driver usable by a boundary schema.Manager. This struct is not thread safe.

func New

func New(ctx context.Context, db *sql.DB) (*Postgres, error)

New creates a Postgres with the provided sql.DB verified as connectable

func (*Postgres) CheckHook added in v0.10.2

CheckHook is a hook that runs prior to a migration's statements. It should run in the same transaction as a corresponding Run call.

func (*Postgres) Close added in v0.10.4

func (p *Postgres) Close() error

Close closes the underlying Postgres database connection.

func (*Postgres) CommitRun

func (p *Postgres) CommitRun(ctx context.Context) error

CommitRun commits a transaction, if there is an error it should rollback the transaction.

func (*Postgres) CurrentState

func (p *Postgres) CurrentState(ctx context.Context, edition string) (version int, initialized bool, err error)

CurrentState returns the state of the given edition. ver is the current migration version number as recorded in the database. A version of -1 indicates no version is set. initialized will be true if the schema was previously initialized.

func (*Postgres) EnsureMigrationLogTable

func (p *Postgres) EnsureMigrationLogTable(ctx context.Context) error

EnsureMigrationLogTable ensures that the table used to record migration lgos exists and is in the correct state.

func (*Postgres) EnsureVersionTable

func (p *Postgres) EnsureVersionTable(ctx context.Context) error

EnsureVersionTable ensures that the table used to record the schema versions for each edition exists and is in the correct state.

func (*Postgres) GetMigrationLog

func (p *Postgres) GetMigrationLog(ctx context.Context, opt ...log.Option) ([]*log.Entry, error)

GetMigrationLog will retrieve the migration logs from the db for the last migration. The WithDeleteLog option is supported and will remove all log entries, after reading the entries, when provided.

func (*Postgres) Lock

func (p *Postgres) Lock(ctx context.Context) error

Lock calls pg_advisory_lock with the provided context and returns an error if we were unable to get the lock before the context cancels.

func (*Postgres) RepairHook added in v0.10.2

RepairHook is a hook that runs prior to a migration's statements. It should run in the same transaction a corresponding Run call.

func (*Postgres) Run

func (p *Postgres) Run(ctx context.Context, migration io.Reader, version int, edition string) error

Run will apply a migration. The io.Reader should provide the SQL statements to execute, and the int is the version for that set of statements. This should always be wrapped by StartRun and CommitRun.

func (*Postgres) StartRun

func (p *Postgres) StartRun(ctx context.Context) error

StartRun begins a transaction internal to the driver.

func (*Postgres) TryLock

func (p *Postgres) TryLock(ctx context.Context) error

TryLock attempts to capture an exclusive lock. If it is not successful it returns an error. https://www.postgresql.org/docs/11/static/explicit-locking.html#ADVISORY-LOCKS

func (*Postgres) TrySharedLock

func (p *Postgres) TrySharedLock(ctx context.Context) error

TrySharedLock attempts to capture a shared lock. If it is not successful it returns an error. https://www.postgresql.org/docs/11/static/explicit-locking.html#ADVISORY-LOCKS

func (*Postgres) Unlock

func (p *Postgres) Unlock(ctx context.Context) error

Unlock calls pg_advisory_unlock and returns an error if we were unable to release the lock before the context cancels.

func (*Postgres) UnlockShared

func (p *Postgres) UnlockShared(ctx context.Context) error

UnlockShared calls pg_advisory_unlock_shared and returns an error if we were unable to release the lock before the context cancels.

Jump to

Keyboard shortcuts

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