postgres

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2021 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

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, instance *sql.DB) (*Postgres, error)

New returns a postgres pointer with the provided db verified as connectable and a version table being initialized.

func (*Postgres) CommitRun

func (p *Postgres) CommitRun() error

CommitRun commits the pending transaction if there is one

func (*Postgres) CurrentState

func (p *Postgres) CurrentState(ctx context.Context) (version int, previouslyRan, dirty bool, err error)

CurrentState returns the version, if the database was ever initialized previously, if it is currently in a dirty state, and any error. A version value of -1 indicates no version is set.

func (*Postgres) EnsureVersionTable

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

EnsureVersionTable checks if versions table exists and, if not, creates it.

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) Rollback

func (p *Postgres) Rollback() error

Rollback rolls back the outstanding transaction. Calling Rollback when there is not an outstanding transaction is an error.

func (*Postgres) Run

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

Run executes the sql provided in the passed in io.Reader. The contents of the reader must fit in memory as the full content is read into a string before being passed to the backing database. EnsureVersionTable should be ran prior to this call.

func (*Postgres) StartRun

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

StartRun starts a transaction that all subsequent calls to Run will use.

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/9.6/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/9.6/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