dump

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dump reads a live PostgreSQL database back into a schema.Schema by way of `pg_dump --schema-only`, and gives schema text a canonical form: the dump of a fresh PostgreSQL the text was applied to.

The loader reads DDL as written; PostgreSQL stores it after analysis (explicit casts, `IN (...)` as `= ANY (ARRAY[...])`, qualified type names). Two schemas can only be compared object by object when both went through PostgreSQL, so diff and apply work on Canonical forms, and Load reads the live side the same way. The `-- sqlshape:` directives live in comments and do not survive the round trip: a canonical schema carries only what PostgreSQL holds.

Seeded tables (schema.Relation.Seed, the rows schema.sql gives a lookup table) are data, which pg_dump --schema-only leaves out; both readers take the seed declarations of a schema and read those tables' declared columns back as INSERT statements appended to the dump, so content compares like the rest.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Binary

func Binary() string

Binary is the pg_dump executable: $SQLSHAPE_PG_DUMP, else "pg_dump" on PATH. The embedded PostgreSQL ships without client tools, so the caller's installation is used; its major version must be at least the server's.

func Canonical

func Canonical(ctx context.Context, schemaSQL string, seeds *schema.Schema) (*schema.Schema, string, error)

Canonical applies schemaSQL to a fresh PostgreSQL and reads it back. The returned text is the normalized dump the Schema was loaded from, followed by the rows of the seeded tables (see Load; nil takes the seeds schemaSQL itself declares). Each call boots its own server; for several canonical forms use one Server.

func Load

func Load(ctx context.Context, connString string, seeds *schema.Schema) (*schema.Schema, string, error)

Load reads the database at connString into a Schema, and returns the normalized dump text it was loaded from. seeds names the tables whose rows are part of the schema (the relations with a schema.Seed, typically the target's): their declared columns are read back as INSERT statements so the content compares like the rest; nil reads no rows.

func Normalize

func Normalize(text string) string

Normalize turns pg_dump output into text the loader parses: psql meta-commands (`\restrict` / `\unrestrict` since 17.6) go, and the search_path set through set_config becomes a SET.

func Run

func Run(ctx context.Context, connString string) (string, error)

Run dumps the schema of the database at connString as SQL text (owners, privileges and tablespaces left out).

func ServerVersion added in v1.2.0

func ServerVersion(ctx context.Context, connString string) (string, error)

ServerVersion asks the database at connString which PostgreSQL it runs ("17.5").

Types

type Canonicalizer

type Canonicalizer interface {
	Canonical(ctx context.Context, schemaSQL string, seeds *schema.Schema) (*schema.Schema, string, error)
}

Canonicalizer gives schema text its canonical form. Server is the implementation; Canonical below is the one-shot convenience.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is one running PostgreSQL that canonicalizes many schema texts, each in a database of its own (booting a server costs seconds, CREATE DATABASE milliseconds).

func NewServer

func NewServer(ctx context.Context, v pgparse.Version) (*Server, error)

NewServer boots the PostgreSQL of major version v. Close it when done.

func (*Server) Canonical

func (s *Server) Canonical(ctx context.Context, schemaSQL string, seeds *schema.Schema) (*schema.Schema, string, error)

Canonical applies schemaSQL to a fresh database on the server and reads it back. Safe for concurrent use.

func (*Server) Close

func (s *Server) Close() error

Close stops the server and removes its data.

Jump to

Keyboard shortcuts

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