Documentation
¶
Overview ¶
Package lspostgres has a libschema.Driver support PostgreSQL
Index ¶
- func Computed(name string, action func(context.Context, *sql.Tx) error, ...) libschema.Migration
- func Generate(name string, generator func(context.Context, *sql.Tx) string, ...) libschema.Migration
- func New(log *internal.Log, dbName string, schema *libschema.Schema, db *sql.DB) (*libschema.Database, error)
- func Script(name string, sqlText string, opts ...libschema.MigrationOption) libschema.Migration
- type Postgres
- func (p *Postgres) CreateSchemaTableIfNotExists(ctx context.Context, _ *internal.Log, d *libschema.Database) error
- func (p *Postgres) DoOneMigration(ctx context.Context, log *internal.Log, d *libschema.Database, ...) (result sql.Result, err error)
- func (p *Postgres) IsMigrationSupported(d *libschema.Database, _ *internal.Log, migration libschema.Migration) error
- func (p *Postgres) LoadStatus(ctx context.Context, _ *internal.Log, d *libschema.Database) (_ []libschema.MigrationName, err error)
- func (p *Postgres) LockMigrationsTable(ctx context.Context, _ *internal.Log, d *libschema.Database) error
- func (p *Postgres) UnlockMigrationsTable(_ *internal.Log) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Computed ¶
func Computed( name string, action func(context.Context, *sql.Tx) error, opts ...libschema.MigrationOption, ) libschema.Migration
Computed creates a libschema.Migration from a Go function to run the migration directly.
func Generate ¶
func Generate( name string, generator func(context.Context, *sql.Tx) string, opts ...libschema.MigrationOption, ) libschema.Migration
Generate creates a libschema.Migration from a function that returns a SQL string
Types ¶
type Postgres ¶
type Postgres struct {
// contains filtered or unexported fields
}
Postgres is a libschema.Driver for connecting to Postgres-like databases that have the following characteristics: * Can do DDL commands inside transactions * Support UPSERT using INSERT ... ON CONFLICT
func (*Postgres) CreateSchemaTableIfNotExists ¶
func (p *Postgres) CreateSchemaTableIfNotExists(ctx context.Context, _ *internal.Log, d *libschema.Database) error
CreateSchemaTableIfNotExists creates the migration tracking table for libschema. It is expected to be called by libschema.
func (*Postgres) DoOneMigration ¶
func (p *Postgres) DoOneMigration(ctx context.Context, log *internal.Log, d *libschema.Database, m libschema.Migration) (result sql.Result, err error)
DoOneMigration applies a single migration. It is expected to be called by libschema.
func (*Postgres) IsMigrationSupported ¶
func (p *Postgres) IsMigrationSupported(d *libschema.Database, _ *internal.Log, migration libschema.Migration) error
IsMigrationSupported checks to see if a migration is well-formed. Absent a code change, this should always return nil. It is expected to be called by libschema.
func (*Postgres) LoadStatus ¶
func (p *Postgres) LoadStatus(ctx context.Context, _ *internal.Log, d *libschema.Database) (_ []libschema.MigrationName, err error)
LoadStatus loads the current status of all migrations from the migration tracking table. It is expected to be called by libschema.