Documentation ¶
Index ¶
- type Postgres
- func (p *Postgres) CommitRun() error
- func (p *Postgres) CurrentState(ctx context.Context) (version int, previouslyRan, dirty bool, err error)
- func (p *Postgres) EnsureVersionTable(ctx context.Context) (err error)
- func (p *Postgres) Lock(ctx context.Context) error
- func (p *Postgres) Rollback() error
- func (p *Postgres) Run(ctx context.Context, migration io.Reader, version int) error
- func (p *Postgres) StartRun(ctx context.Context) error
- func (p *Postgres) TryLock(ctx context.Context) error
- func (p *Postgres) TrySharedLock(ctx context.Context) error
- func (p *Postgres) Unlock(ctx context.Context) error
- func (p *Postgres) UnlockShared(ctx context.Context) error
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 ¶
New returns a postgres pointer with the provided db verified as connectable and a version table being initialized.
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 ¶
EnsureVersionTable checks if versions table exists and, if not, creates it.
func (*Postgres) Lock ¶
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 ¶
Rollback rolls back the outstanding transaction. Calling Rollback when there is not an outstanding transaction is an error.
func (*Postgres) Run ¶
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 ¶
StartRun starts a transaction that all subsequent calls to Run will use.
func (*Postgres) TryLock ¶
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 ¶
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