lspostgres

package
v0.0.0-...-7c9577e Latest Latest
Warning

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

Go to latest
Published: May 23, 2025 License: MIT Imports: 9 Imported by: 0

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, dbName string, schema *libschema.Schema, db *sql.DB) (*libschema.Database, error)

New creates a libschema.Database with a postgres driver built in. The dbName parameter is used internally by libschema, but does not affect where migrations are actually applied.

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

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.

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