postgresql

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: GPL-3.0 Imports: 40 Imported by: 0

Documentation

Overview

Package postgresql implements the PostgreSQL 15+ physical-schema provider. Every identifier and expression accepted by this package originates in the validated physical schema; no API accepts caller-authored SQL.

Index

Constants

View Source
const (
	CapabilityPolicyBinaryText          = "policy.binary-text.v1"
	CapabilityPolicyASCIIInsensitive    = "policy.ascii-insensitive-text.v1"
	CapabilityPolicyExactJSON           = "policy.exact-json.v1"
	CapabilityPolicyScalarListJSON      = "scalar-list.json-array.v1"
	CapabilityPolicyRelationCorrelation = "policy.relation-correlation.v1"
)
View Source
const (
	CapabilityJSONB            ir.CapabilityID = "postgresql.jsonb"
	CapabilityGeneratedColumns ir.CapabilityID = "postgresql.generated_columns"
	CapabilityAdvisoryLocks    ir.CapabilityID = "postgresql.advisory_xact_lock"
	CapabilityAnalyticsExact   ir.CapabilityID = "analytics.exact-arithmetic.v1"
)

Variables

This section is empty.

Functions

func CaptureQueryPlan added in v0.1.0

func CaptureQueryPlan(ctx context.Context, connection *sqlx.Conn, statement string, arguments []any, registry *schema.Registry, aliases queryplancapture.AliasMap) (queryplancapture.Plan, error)

CaptureQueryPlan owns and closes the single EXPLAIN row before returning. The caller owns connection and releases it after this function returns.

Types

type CapabilityReport

type CapabilityReport struct {
	Version             physical.Version
	JSONB               bool
	GeneratedColumns    bool
	AdvisoryLocks       bool
	BinaryText          bool
	ASCIIInsensitive    bool
	ExactJSON           bool
	ScalarListJSON      bool
	RelationCorrelation bool
	AnalyticsExact      bool
	SessionSettings     bool
}

type IncrementalPlan

type IncrementalPlan struct {
	MigrationID migration.MigrationID
	// contains filtered or unexported fields
}

IncrementalPlan is immutable provider-generated PostgreSQL DDL for one reviewed migration entry. SQL is exposed for review, never accepted as input.

func (IncrementalPlan) SQL

func (plan IncrementalPlan) SQL() string

SQL renders the reviewed artifact. Companion seams appear as deterministic comments: their bytes live in the separately checksummed companion file and are never copied into, or accepted from, this artifact.

type PolicyDialect

type PolicyDialect struct{}

PolicyDialect renders the closed P2 predicate vocabulary for PostgreSQL 15+. It is stateless: all runtime capability evidence is carried by the fingerprint-bound CapabilityProof passed to the shared compiler.

func NewPolicyDialect

func NewPolicyDialect() PolicyDialect

func (PolicyDialect) Encode

func (PolicyDialect) Encode(bound policysql.BoundValue) (any, error)

func (PolicyDialect) Placeholder

func (PolicyDialect) Placeholder(position int) string

func (PolicyDialect) Provider

func (PolicyDialect) Provider() policyir.Provider

func (PolicyDialect) Quote

func (PolicyDialect) RenderJSON

func (dialect PolicyDialect) RenderJSON(leaf policysql.JSONLeaf, binder *policysql.Binder) (string, error)

func (PolicyDialect) RenderList

func (dialect PolicyDialect) RenderList(leaf policysql.ListLeaf, binder *policysql.Binder) (string, error)

func (PolicyDialect) RenderScalar

func (dialect PolicyDialect) RenderScalar(leaf policysql.ScalarLeaf, binder *policysql.Binder) (string, error)

func (PolicyDialect) Supports

func (PolicyDialect) Supports(operator policyir.OperatorID) bool

func (PolicyDialect) Table

func (PolicyDialect) Table(model policysql.Model) string

type Provider

type Provider struct{}

func New

func New() *Provider

func (*Provider) ApplyInitial

func (provider *Provider) ApplyInitial(ctx context.Context, database *sqlx.DB, schema physical.PhysicalSchema) error

func (*Provider) ApplyMigration

func (provider *Provider) ApplyMigration(ctx context.Context, database *sqlx.DB, manifest migration.Manifest, files map[string][]byte) error

ApplyMigration verifies immutable history and applies exactly the next reviewed entry. It never skips or batches ledger entries.

func (*Provider) EventCoordinator

func (*Provider) EventCoordinator(database *sqlx.DB) (eventprovider.Coordinator, error)

func (*Provider) EventCoordinatorAt

func (*Provider) EventCoordinatorAt(database *sqlx.DB, namespace physical.PhysicalName) (eventprovider.Coordinator, error)

EventCoordinatorAt exists for generated schemas whose reviewed system namespace differs from the default. The namespace must already be a closed physical identifier; no application value can become SQL.

func (*Provider) Introspect

func (provider *Provider) Introspect(ctx context.Context, database *sqlx.DB, expected physical.PhysicalSchema) (physical.PhysicalSchema, error)

func (*Provider) Lower

func (provider *Provider) Lower(ctx context.Context, model ir.ModelIR, options physical.LowerOptions) (physical.PhysicalSchema, error)

func (*Provider) Manifest

func (*Provider) Manifest() physical.ProviderManifest

func (*Provider) Open

func (provider *Provider) Open(ctx context.Context, dataSourceName string) (*sqlx.DB, CapabilityReport, error)

func (*Provider) PlanIncremental

func (provider *Provider) PlanIncremental(entry migration.ManifestEntry) (IncrementalPlan, error)

PlanIncremental lowers an already reviewed semantic migration entry. It does not invent casts, transforms, rebuilds, manual SQL, or autocommit phases.

func (*Provider) PolicyCapabilityProof

func (provider *Provider) PolicyCapabilityProof(ctx context.Context, database *sqlx.DB, fingerprint [32]byte) (policysql.CapabilityProof, error)

func (*Provider) QueueStore added in v0.3.0

func (*Provider) QueueStore(database *sqlx.DB) (queueprovider.Store, error)

QueueStore binds the durable job state machine to a live PostgreSQL database in the default system namespace.

func (*Provider) QueueStoreAt added in v0.3.0

func (*Provider) QueueStoreAt(database *sqlx.DB, namespace physical.PhysicalName) (queueprovider.Store, error)

QueueStoreAt exists for generated schemas whose reviewed system namespace differs from the default. The namespace must already be a closed physical identifier; no application value can become SQL.

func (*Provider) ReadLedger

func (*Provider) ReadLedger(ctx context.Context, database *sqlx.DB) ([]migration.LedgerEntry, error)

ReadLedger returns the exact ordered PostgreSQL migration chain.

func (*Provider) ReadLedgerForSchema

func (*Provider) ReadLedgerForSchema(ctx context.Context, database *sqlx.DB, system physical.SystemSchema) ([]migration.LedgerEntry, error)

ReadLedgerForSchema reads the ledger identified by the selected generated physical schema, including its exact namespace. Runtime startup must use this path rather than assuming the provider's default namespace.

func (*Provider) RenderInitial

func (provider *Provider) RenderInitial(schema physical.PhysicalSchema) (Script, error)

func (*Provider) RenderMigration added in v0.1.0

func (provider *Provider) RenderMigration(entry migration.ManifestEntry) (Script, error)

RenderMigration returns the exact provider DDL reviewed for one sealed typed entry. Historical snapshots are reachable only through this entry-bound seam; the public RenderInitial surface remains current-format-only.

func (*Provider) VerifiedPoolPolicyCapabilityProof

func (provider *Provider) VerifiedPoolPolicyCapabilityProof(ctx context.Context, database *sqlx.DB, fingerprint [32]byte, width int) (policysql.CapabilityProof, error)

func (*Provider) Verify

func (provider *Provider) Verify(ctx context.Context, database *sqlx.DB, expected physical.PhysicalSchema) error

func (*Provider) VerifyPool

func (*Provider) VerifyPool(ctx context.Context, database *sqlx.DB, width int) (CapabilityReport, error)

VerifyPool proves every sealed pool slot while holding the entire bounded pool. Any existing borrower or acquisition wait invalidates startup.

type Script

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

Script is immutable provider-generated DDL. Its statement list is not exported, so application input cannot be smuggled into migration execution.

func (Script) SQL

func (script Script) SQL() string

Jump to

Keyboard shortcuts

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