Documentation ¶
Overview ¶
Package postgres provides an implementation of the schema.driver interface for a PostgreSQL database.
Index ¶
- type Postgres
- func (p *Postgres) CommitRun(ctx context.Context) error
- func (p *Postgres) CurrentState(ctx context.Context, edition string) (version int, initialized bool, err error)
- func (p *Postgres) EnsureMigrationLogTable(ctx context.Context) error
- func (p *Postgres) EnsureVersionTable(ctx context.Context) error
- func (p *Postgres) GetMigrationLog(ctx context.Context, opt ...log.Option) ([]*log.Entry, error)
- func (p *Postgres) Lock(ctx context.Context) error
- func (p *Postgres) Run(ctx context.Context, migration io.Reader, version int, edition string) 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 (*Postgres) CommitRun ¶
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 ¶
EnsureMigrationLogTable ensures that the table used to record migration lgos exists and is in the correct state.
func (*Postgres) EnsureVersionTable ¶
EnsureVersionTable ensures that the table used to record the schema versions for each edition exists and is in the correct state.
func (*Postgres) GetMigrationLog ¶
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 ¶
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) Run ¶
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) TryLock ¶
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 ¶
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