Skip to content

Schema Types

ColumnDefinition

Type: Object

Properties

  • name string The name of the column.
  • type string PostgreSQL data type (e.g., 'text', 'uuid', 'integer', 'varchar', 'jsonb').
  • generated ("always" | "by default")? Marks the column as a generated column.
  • expression string? SQL expression used for the generated column.
  • stored boolean? Whether the generated column should be stored.
  • notNull boolean? Whether the column accepts null values. Defaults to false.
  • default any? Default value for the column. Can be a literal or SQL expression.
  • immutable boolean? If true, the column cannot be updated after creation. Defaults to false.
  • colProps Object? Extended column behavior modifiers.

    • colProps.mod string? pg-promise format modifier.
    • colProps.cnd boolean? Use in conditional update clause.
    • colProps.def string? Override default value.
    • colProps.validator any? Custom Zod validator for this column.

ConstraintDefinition

Type: Object

Properties

  • type ("PrimaryKey" | "ForeignKey" | "Unique" | "Check" | "Index") Type of constraint.
  • columns Array<string> List of column names the constraint applies to.
  • references {table: string, columns: Array<string>}? For foreign keys.
  • onDelete string? Optional ON DELETE behavior (e.g., 'CASCADE').
  • expression string? SQL expression for check constraints.

Constraints

Type: Object

Properties

AuditFieldsConfig

Type: Object

Properties

  • enabled boolean Whether to include audit fields.
  • userFields Object? Configuration for user tracking fields (created_by, updated_by).

    • userFields.type string? PostgreSQL data type for user fields (e.g., 'uuid', 'varchar(50)', 'int'). Defaults to 'varchar(50)'.
    • userFields.nullable boolean? Whether user fields can be null. Defaults to true.
    • userFields.default any? Default value for user fields. Defaults to null.

TableSchema

Type: Object

Properties

  • dbSchema string PostgreSQL schema name (e.g., 'public').
  • table string Table name.
  • hasAuditFields (boolean | AuditFieldsConfig)? Whether to include created_at/updated_at/by fields. Accepts boolean for backward compatibility or object for configuration.
  • softDelete boolean? Whether to use a soft delete strategy.
  • version string? Optional schema version string.
  • columns Array<ColumnDefinition> List of column definitions.
  • constraints Constraints? Table-level constraints.