schema

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package schema defines the in-memory representation of a PostgreSQL database schema. These structs form the "AST" that the introspection engine populates and the diff engine compares.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column struct {
	Name      string
	Type      string // full type string as PG stores it (e.g., "character varying(255)")
	Nullable  bool
	Default   string // expression string or empty
	Identity  *Identity
	Generated *Generated
	Collation string
	Comment   string
}

Column represents a table column.

type Constraint

type Constraint struct {
	Name             string
	Type             ConstraintType
	Columns          []string // column names for PK/unique
	Expression       string   // for check constraints
	NullsNotDistinct bool     // PG15+ NULLS NOT DISTINCT for unique
	Comment          string
}

Constraint represents a table constraint (PK, unique, check, exclusion).

type ConstraintType

type ConstraintType int

ConstraintType classifies a constraint.

const (
	ConstraintPK ConstraintType = iota
	ConstraintUnique
	ConstraintCheck
	ConstraintExclusion
)

type Database

type Database struct {
	Schemas    []*Schema
	Extensions []*Extension
}

Database is the top-level container representing an entire PostgreSQL database. It holds all schemas (namespaces), extensions, and enums.

type Enum

type Enum struct {
	Schema string
	Name   string
	Values []string // ordered list of enum labels
}

Enum represents a PostgreSQL enum type.

type Extension

type Extension struct {
	Name    string
	Version string // installed version; empty means default
	Schema  string // schema it's installed into
}

Extension represents a PostgreSQL extension (e.g., pgcrypto, uuid-ossp).

type ForeignKey

type ForeignKey struct {
	Name              string
	Columns           []string
	RefSchema         string
	RefTable          string
	RefColumns        []string
	OnUpdate          string // CASCADE, RESTRICT, SET NULL, SET DEFAULT, NO ACTION
	OnDelete          string
	Deferrable        bool
	InitiallyDeferred bool
	Comment           string
}

ForeignKey represents a foreign key constraint.

type Function

type Function struct {
	Schema     string
	Name       string
	Args       string // full argument signature (e.g., "integer, text")
	Returns    string // return type
	Language   string // plpgsql, sql, etc.
	Body       string // function body
	Volatility string // VOLATILE, STABLE, IMMUTABLE
	Security   string // INVOKER, DEFINER
	IsProc     bool   // true if PROCEDURE, false if FUNCTION
	Comment    string
}

Function represents a PostgreSQL function or procedure.

type Generated

type Generated struct {
	Expression string
}

Generated represents a GENERATED ALWAYS AS (expr) STORED column.

type Identity

type Identity struct {
	Always    bool // true = GENERATED ALWAYS, false = GENERATED BY DEFAULT
	Start     int64
	Increment int64
	MinValue  int64
	MaxValue  int64
	Cache     int64
	Cycle     bool
}

Identity represents a column's GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY properties.

type Index

type Index struct {
	Name      string
	Method    IndexMethod
	Unique    bool
	Columns   []*IndexColumn
	Predicate string   // WHERE clause for partial indexes
	Include   []string // INCLUDE columns (covering index)
	Comment   string
}

Index represents a table index.

type IndexColumn

type IndexColumn struct {
	Column     string // column name (empty if expression)
	Expression string // expression (empty if column)
	OpClass    string // operator class (e.g., "text_pattern_ops")
	Order      string // ASC, DESC, or empty for default
	NullsOrder string // NULLS FIRST, NULLS LAST, or empty
}

IndexColumn represents one column/expression in an index.

type IndexMethod

type IndexMethod string

IndexMethod represents the index access method.

const (
	IndexBTree  IndexMethod = "btree"
	IndexHash   IndexMethod = "hash"
	IndexGIN    IndexMethod = "gin"
	IndexGiST   IndexMethod = "gist"
	IndexSPGiST IndexMethod = "spgist"
	IndexBRIN   IndexMethod = "brin"
)

type MaterializedView

type MaterializedView struct {
	Schema     string
	Name       string
	Definition string
	Indexes    []*Index
	Comment    string
}

MaterializedView represents a PostgreSQL materialized view.

type Schema

type Schema struct {
	Name              string
	Tables            []*Table
	Enums             []*Enum
	Sequences         []*Sequence
	Views             []*View
	MaterializedViews []*MaterializedView
	Functions         []*Function
	Triggers          []*Trigger
}

Schema represents a PostgreSQL namespace (e.g., "public", "auth"). It is a first-class diffable object.

type Sequence

type Sequence struct {
	Schema    string
	Name      string
	DataType  string // smallint, integer, bigint
	Start     int64
	Increment int64
	MinValue  int64
	MaxValue  int64
	Cache     int64
	Cycle     bool
	OwnedBy   string // "table.column" or empty
}

Sequence represents a PostgreSQL sequence.

type Table

type Table struct {
	Schema      string
	Name        string
	Columns     []*Column
	PrimaryKey  *Constraint
	Constraints []*Constraint
	Indexes     []*Index
	ForeignKeys []*ForeignKey
	Comment     string
}

Table represents a PostgreSQL table.

type Trigger

type Trigger struct {
	Schema     string
	Table      string
	Name       string
	Timing     string   // BEFORE, AFTER, INSTEAD OF
	Events     []string // INSERT, UPDATE, DELETE, TRUNCATE
	ForEachRow bool
	When       string // WHEN condition
	Function   string // function to call (schema-qualified)
	Comment    string
}

Trigger represents a PostgreSQL trigger.

type View

type View struct {
	Schema     string
	Name       string
	Definition string // the SELECT query
	Comment    string
}

View represents a PostgreSQL view.

Jump to

Keyboard shortcuts

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