lspostgres

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2022 License: MIT Imports: 8 Imported by: 1

Documentation

Overview

Package lspostgres has a libschema.Driver support PostgreSQL

Index

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

func New

func New(log *internal.Log, name string, schema *libschema.Schema, db *sql.DB) (*libschema.Database, error)

New creates a libschema.Database with a postgres driver built in.

func Script

func Script(name string, sqlText string, opts ...libschema.MigrationOption) libschema.Migration

Script creates a libschema.Migration from 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

LoadStatus loads the current status of all migrations from the migration tracking table. It is expected to be called by libschema.

func (*Postgres) LockMigrationsTable

func (p *Postgres) LockMigrationsTable(ctx context.Context, _ *internal.Log, d *libschema.Database) error

LockMigrationsTable locks the migration tracking table for exclusive use by the migrations running now. It is expected to be called by libschema.

func (*Postgres) UnlockMigrationsTable

func (p *Postgres) UnlockMigrationsTable(_ *internal.Log) error

UnlockMigrationsTable unlocks the migration tracking table. It is expected to be called by libschema.

Jump to

Keyboard shortcuts

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