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
- func CaptureQueryPlan(ctx context.Context, connection *sqlx.Conn, statement string, arguments []any, ...) (queryplancapture.Plan, error)
- type CapabilityReport
- type IncrementalPlan
- type PolicyDialect
- func (PolicyDialect) Encode(bound policysql.BoundValue) (any, error)
- func (PolicyDialect) Placeholder(position int) string
- func (PolicyDialect) Provider() policyir.Provider
- func (PolicyDialect) Quote(name physical.PhysicalName) string
- func (dialect PolicyDialect) RenderJSON(leaf policysql.JSONLeaf, binder *policysql.Binder) (string, error)
- func (dialect PolicyDialect) RenderList(leaf policysql.ListLeaf, binder *policysql.Binder) (string, error)
- func (dialect PolicyDialect) RenderScalar(leaf policysql.ScalarLeaf, binder *policysql.Binder) (string, error)
- func (PolicyDialect) Supports(operator policyir.OperatorID) bool
- func (PolicyDialect) Table(model policysql.Model) string
- type Provider
- func (provider *Provider) ApplyInitial(ctx context.Context, database *sqlx.DB, schema physical.PhysicalSchema) error
- func (provider *Provider) ApplyMigration(ctx context.Context, database *sqlx.DB, manifest migration.Manifest, ...) error
- func (*Provider) EventCoordinator(database *sqlx.DB) (eventprovider.Coordinator, error)
- func (*Provider) EventCoordinatorAt(database *sqlx.DB, namespace physical.PhysicalName) (eventprovider.Coordinator, error)
- func (provider *Provider) Introspect(ctx context.Context, database *sqlx.DB, expected physical.PhysicalSchema) (physical.PhysicalSchema, error)
- func (provider *Provider) Lower(ctx context.Context, model ir.ModelIR, options physical.LowerOptions) (physical.PhysicalSchema, error)
- func (*Provider) Manifest() physical.ProviderManifest
- func (provider *Provider) Open(ctx context.Context, dataSourceName string) (*sqlx.DB, CapabilityReport, error)
- func (provider *Provider) PlanIncremental(entry migration.ManifestEntry) (IncrementalPlan, error)
- func (provider *Provider) PolicyCapabilityProof(ctx context.Context, database *sqlx.DB, fingerprint [32]byte) (policysql.CapabilityProof, error)
- func (*Provider) QueueStore(database *sqlx.DB) (queueprovider.Store, error)
- func (*Provider) QueueStoreAt(database *sqlx.DB, namespace physical.PhysicalName) (queueprovider.Store, error)
- func (*Provider) ReadLedger(ctx context.Context, database *sqlx.DB) ([]migration.LedgerEntry, error)
- func (*Provider) ReadLedgerForSchema(ctx context.Context, database *sqlx.DB, system physical.SystemSchema) ([]migration.LedgerEntry, error)
- func (provider *Provider) RenderInitial(schema physical.PhysicalSchema) (Script, error)
- func (provider *Provider) RenderMigration(entry migration.ManifestEntry) (Script, error)
- func (provider *Provider) VerifiedPoolPolicyCapabilityProof(ctx context.Context, database *sqlx.DB, fingerprint [32]byte, width int) (policysql.CapabilityProof, error)
- func (provider *Provider) Verify(ctx context.Context, database *sqlx.DB, expected physical.PhysicalSchema) error
- func (*Provider) VerifyPool(ctx context.Context, database *sqlx.DB, width int) (CapabilityReport, error)
- type Script
Constants ¶
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" )
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 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) Quote(name physical.PhysicalName) string
func (PolicyDialect) RenderJSON ¶
func (PolicyDialect) RenderList ¶
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
type Provider ¶
type Provider struct{}
func (*Provider) ApplyInitial ¶
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) 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) QueueStore ¶ added in v0.3.0
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) 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.