pgutil

package
v1.39.1 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TransferOwnership

func TransferOwnership(ctx context.Context, ex Execer, logPrefix, table string)

TransferOwnership runs ALTER TABLE <table> OWNER TO CURRENT_USER as an idempotent fail-soft op.

Best-effort: if the connected role is not the current table owner (common after a restore where a superuser created the tables), the ALTER fails with SQLSTATE 42501 (insufficient_privilege) and we log a warning instead of returning an error. All other errors are also logged as warnings and swallowed — ownership transfer is advisory; callers must rely on explicit DML grants as the hard guarantee.

logPrefix is prepended to log messages (e.g. "codegraph", "embeddings") so log lines stay attributable to the calling subsystem.

The SQL keyword CURRENT_USER is a Postgres built-in, not a bind parameter, so it resolves to the connected role regardless of the DATABASE_URL role name.

NOTE: The string "CURRENT_USER" must appear in the generated SQL — tests assert this to prevent accidental hardcoding of a role name.

Types

type Execer

type Execer interface {
	Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
}

Execer is the minimal pgx surface TransferOwnership needs. *pgxpool.Conn, *pgxpool.Pool, and pgx.Tx all satisfy this interface.

Directories

Path Synopsis
Package pgtest holds shared test-only helpers for pgvector store integration tests (analogous in spirit to stdlib's net/http/httptest: a dedicated test-support package, never imported by production code).
Package pgtest holds shared test-only helpers for pgvector store integration tests (analogous in spirit to stdlib's net/http/httptest: a dedicated test-support package, never imported by production code).

Jump to

Keyboard shortcuts

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