QuoteIdent quotes a PostgreSQL identifier with double-quotes if needed. Quoting is applied when the name is a reserved word, contains special characters, has uppercase letters, or starts with a digit.
QualifiedName returns a schema-qualified name with proper quoting. An empty schema yields the UNQUALIFIED name: quoting an empty string produces "", which would render the invalid "".table — so the guard lives here, centrally, killing that class for every caller.
LiteralValue formats a value as a SQL literal based on its PG type. Strings get single quotes (with escaping), numbers are bare, booleans are bare, and empty values return "NULL".
CreateEnum generates a CREATE TYPE ... AS ENUM statement. PostgreSQL does not support CREATE TYPE IF NOT EXISTS, so when idempotent is true, the statement is wrapped in a DO $$ block that checks pg_type before creating (same approach as CreateDomain and CreateCompositeType).
CreateDomain generates a CREATE DOMAIN statement. Emits: CREATE DOMAIN [schema.]name AS basetype [NOT NULL] [DEFAULT ...] [CHECK (...)]. When idempotent is true, wraps in a DO $$ block that checks pg_type before creating.
CreateCompositeType generates a CREATE TYPE ... AS statement for a composite type. Emits: CREATE TYPE [schema.]name AS (field1 type1, field2 type2, ...) When idempotent is true, wraps in a DO $$ block that checks pg_type before creating.
CreateTable generates a CREATE TABLE statement with columns, inline PK, and PARTITION BY. Foreign keys are NOT included (they use ALTER TABLE for cycle safety). pgVersion controls version-specific DDL: when the target version lacks identity column support (pre-PG10), identity columns fall back to bigserial. enums and domains are the enum and domain types defined in the schema; when a column's PG type matches an enum or domain name, the type is emitted with its schema prefix so the DDL works without relying on search_path.
AlterTableAddColumnIfNotExists generates an ALTER TABLE ... ADD COLUMN IF NOT EXISTS statement. This is used in idempotent mode to ensure columns exist without erroring if they already do. The column definition reuses the same columnDef logic as CreateTable.
AlterTableAddFK generates an ALTER TABLE ... ADD CONSTRAINT ... FOREIGN KEY statement. When idempotent is true, wraps the statement in a DO $$ block that checks pg_constraint before adding.
AlterTableAddUnique generates an ALTER TABLE ... ADD CONSTRAINT ... UNIQUE statement. When idempotent is true, wraps the statement in a DO $$ block that checks pg_constraint before adding.
AlterTableAddCheck generates an ALTER TABLE ... ADD CONSTRAINT ... CHECK statement. When idempotent is true, wraps the statement in a DO $$ block that checks pg_constraint before adding.
CreateIndex generates a CREATE INDEX statement. Handles Method (default btree), per-column Opclasses, WHERE, INCLUDE, and CONCURRENTLY. When concurrently is true, IF NOT EXISTS is DELIBERATELY omitted (not for version reasons — CREATE INDEX CONCURRENTLY IF NOT EXISTS is valid since PG 9.5): an interrupted CREATE INDEX CONCURRENTLY leaves an INVALID index of the target name, and IF NOT EXISTS would skip it forever. The resume protocol instead checks pg_index.indisvalid and DROP-rebuilds (roadmap L8), so the bare form is correct here.
CommentsOnTable returns the COMMENT ON statements for a table and its columns (table comment first, then per-column comments in column order). It is empty when the table and all its columns are commentless. Callers that render a table's DDL standalone — the migrate chain create_table render path — append these so a chain-created table carries its mandatory comment (and any column comments) live, instead of relying on the full-DDL generate path that emits comments in a separate section.
CreatePartitionOf generates a CREATE TABLE ... PARTITION OF statement for a child partition. The bound expression is emitted verbatim (e.g. "FROM ('2024-01-01') TO ('2024-02-01')").
PartmanRunMaintenanceCron generates a SELECT cron.schedule() call to create a pg_cron job that runs partman.run_maintenance_proc() on the given cron schedule (e.g. "/30 *"). Requires the pg_cron extension.
CreatePolicy generates a CREATE POLICY statement for row-level security. The FOR clause is omitted when operation is "ALL" (the PostgreSQL default). The TO clause is omitted when role is empty (defaults to PUBLIC). USING and WITH CHECK are wrapped in parentheses when present.
When idempotent is true and pgVersion >= 15, uses CREATE OR REPLACE POLICY. When idempotent is true and pgVersion < 15, wraps in a DO $$ block that checks pg_policy before executing.
CreateMaterializedView generates a CREATE MATERIALIZED VIEW statement. PostgreSQL does not support CREATE OR REPLACE or IF NOT EXISTS for materialized views. When idempotent is true, wraps in a DO $$ block that checks pg_matviews before creating.
RefreshMaterializedView generates a REFRESH MATERIALIZED VIEW statement. When concurrently is true, adds CONCURRENTLY (requires a unique index to exist).
CreateDenyMutationFunction generates a CREATE OR REPLACE FUNCTION statement for the shared pgdesign_deny_mutation trigger function. This function raises an exception when UPDATE or DELETE is attempted on an append-only table.
CreateAppendOnlyTrigger generates a CREATE TRIGGER statement that fires BEFORE UPDATE OR DELETE to enforce append-only behavior on a table. When idempotent is true and pgVersion supports CREATE OR REPLACE TRIGGER (PG 14+), it emits CREATE OR REPLACE TRIGGER; otherwise it emits DROP TRIGGER IF EXISTS followed by CREATE TRIGGER.
CreateStateMachineTriggerFunction generates a PL/pgSQL function that enforces state machine transitions on a column. It checks that each UPDATE of the column follows a valid transition and that any required columns are non-null.
CreateStateMachineTrigger generates a CREATE TRIGGER statement that fires BEFORE UPDATE OF
to enforce state machine transitions. When idempotent is true and pgVersion supports CREATE OR REPLACE TRIGGER (PG 14+), it emits CREATE OR REPLACE TRIGGER; otherwise it emits DROP TRIGGER IF EXISTS followed by CREATE TRIGGER.
CreateTrigger generates a CREATE [CONSTRAINT] TRIGGER statement for a user-defined trigger. Emits: CREATE [OR REPLACE] [CONSTRAINT] TRIGGER name timing events ON [schema.]table
[REFERENCING OLD TABLE AS x NEW TABLE AS y] FOR EACH ROW|STATEMENT [WHEN (condition)] EXECUTE FUNCTION [schema.]func_name()
When idempotent is true and pgVersion supports CREATE OR REPLACE TRIGGER (PG 14+), it emits CREATE OR REPLACE [CONSTRAINT] TRIGGER; otherwise it emits DROP TRIGGER IF EXISTS followed by CREATE [CONSTRAINT] TRIGGER.
CreateFunction generates a CREATE OR REPLACE FUNCTION/PROCEDURE statement. For procedures (f.IsProc), RETURNS and volatility/parallel/cost/rows are omitted.