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 ¶
- func Binary() string
- func Canonical(ctx context.Context, schemaSQL string, seeds *schema.Schema) (*schema.Schema, string, error)
- func Load(ctx context.Context, connString string, seeds *schema.Schema) (*schema.Schema, string, error)
- func Normalize(text string) string
- func Run(ctx context.Context, connString string) (string, error)
- func ServerVersion(ctx context.Context, connString string) (string, error)
- type Canonicalizer
- type Server
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 ¶
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.
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).