schema

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const QryVersionUpdate = `
  INSERT INTO __meta__ (version, description) VALUES ($1, $2)
`

QryVersionUpdate inserts the current version and description into the meta table

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager struct {
	DB string
	// contains filtered or unexported fields
}

Manager is a migration manager

func NewManager

func NewManager(dbURL string) *Manager

NewManager creates a new migration manager

func (*Manager) ClearDatabase

func (m *Manager) ClearDatabase(ctx context.Context, db string) error

ClearDatabase drops and creates a database

func (*Manager) Connect

func (m *Manager) Connect(
	ctx context.Context,
	db string,
) (*pgx.Conn, error)

Connect acquires a connection to a database by name

func (*Manager) Migrate

func (m *Manager) Migrate(
	ctx context.Context,
	db string,
) error

Migrate applies all migrations above the starting version

func (*Manager) Status

func (m *Manager) Status(
	ctx context.Context,
) *Status

Status retrievs the information about the state of the db

type Migration

type Migration struct {
	Seq  int
	Name string
	SQL  string
}

A Migration consists of an SQL statement and an ID. The Sequence is the order of the migrations.

type MigrationState

type MigrationState struct {
	AppliedAt   time.Time `json:"applied_at"`
	Description string    `json:"description"`
	Version     int       `json:"version"`
}

MigrationState is the current version of the database and when it was applied.

func MigrationStateFromDB

func MigrationStateFromDB(ctx context.Context, conn *pgx.Conn) (*MigrationState, error)

MigrationStateFromDB reads the current migration state from the meta table.

type Migrations

type Migrations []*Migration

Migrations is a sorted collection of migrations

func GetMigrations

func GetMigrations() Migrations

GetMigrations retrievs all migrations from the embedded filesystem

func (Migrations) Len

func (m Migrations) Len() int

Len implements the sort interface

func (Migrations) Less

func (m Migrations) Less(i, j int) bool

Less implements the sort interface and compares the sequence

func (Migrations) Swap

func (m Migrations) Swap(i, j int)

Swap implements the sort interface

type Status

type Status struct {
	Available         bool            `json:"available"`
	Database          string          `json:"database"`
	Migrated          bool            `json:"migrated"`
	Migration         *MigrationState `json:"migration"`
	PendingMigrations int             `json:"pending_migrations"`
	Error             *string         `json:"error"`
}

Status is the current status of the database

Jump to

Keyboard shortcuts

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