Skip to content

Schema and DDL options ​

Options of QueryInterface and sync: tables, constraints, indexes, partitions, extensions, sequences, functions, triggers, views and row-level security.

Options marked postgrelize extension exist only in postgrelize; Sequelize v6 has no such option. This page is generated from the TypeScript declarations and their TSDoc, so it always matches the code.

CreateTableOptions ​

Options of createTable: a table comment, the table persistence and the common query options.

ts
const options: CreateTableOptions = { comment: 'Blog posts', transaction };
await queryInterface.createTable('posts', { title: DataTypes.STRING }, options);
await queryInterface.createTable('scratch', { n: DataTypes.INTEGER }, { temporary: true, transaction });
await queryInterface.createTable('events', { at: DataTypes.DATE }, { partitionBy: { strategy: 'range', columns: ['at'] } });
OptionTypeDescription
transactionTransactionTransaction to run in; null forces running outside the CLS transaction.
loggingfalse | LoggingFunctionSQL logger for this query, or false.
benchmarkbooleanPass query duration to the logger.
statementTimeout postgrelize extensionnumberstatement_timeout for this query only, in milliseconds (non-negative integer; 0 disables it). PostgreSQL cancels the statement with a DatabaseError (code 57014) when it runs longer. Outside a transaction the query runs in its own short transaction; inside one the previous timeout is restored afterwards. PostgreSQL extension.
retryReadonly<{ max?: number | undefined; match?: readonly RetryMatch[] | undefined; backoff…Retries this query when it fails, merged over the instance retry option (Sequelize v6). The connection acquisition is part of the retried work; a query that runs in a transaction is never retried.
useMaster postgrelize extensionbooleanForce the writer even for SELECTs when read replicas are configured. postgrelize extension.
replacementsReplacementsValues of ? (array) or :name (object) placeholders written in raw SQL inside the options (where: literal('"a" = :a'), attributes: [[literal(...), 'x']]), as in Sequelize v6. Every value is sent as a bound parameter, never concatenated into the SQL text; arrays expand to a comma separated list of parameters.
commentstringTable comment.
unloggedbooleanCREATE UNLOGGED TABLE: not written to the WAL, faster writes, emptied after a crash and not replicated.
temporarybooleanCREATE TEMPORARY TABLE: lives as long as the database session (one pooled connection, so pass a transaction or use pool.max = 1), is dropped automatically and cannot have a schema. Cannot be combined with unlogged.
partitionByReadonly<{ strategy: PartitionStrategy; columns: readonly PartitionKeyElement[]; }>PARTITION BY RANGE | LIST | HASH (...): creates a partitioned table; add partitions with createPartition. PostgreSQL requires primary and unique keys to include the partition columns.

DropTableOptions ​

Options of dropTable: cascade plus the common query options.

ts
const options: DropTableOptions = { cascade: true };
await queryInterface.dropTable('posts', options);
OptionTypeDescription
transactionTransactionTransaction to run in; null forces running outside the CLS transaction.
loggingfalse | LoggingFunctionSQL logger for this query, or false.
benchmarkbooleanPass query duration to the logger.
statementTimeout postgrelize extensionnumberstatement_timeout for this query only, in milliseconds (non-negative integer; 0 disables it). PostgreSQL cancels the statement with a DatabaseError (code 57014) when it runs longer. Outside a transaction the query runs in its own short transaction; inside one the previous timeout is restored afterwards. PostgreSQL extension.
retryReadonly<{ max?: number | undefined; match?: readonly RetryMatch[] | undefined; backoff…Retries this query when it fails, merged over the instance retry option (Sequelize v6). The connection acquisition is part of the retried work; a query that runs in a transaction is never retried.
useMaster postgrelize extensionbooleanForce the writer even for SELECTs when read replicas are configured. postgrelize extension.
replacementsReplacementsValues of ? (array) or :name (object) placeholders written in raw SQL inside the options (where: literal('"a" = :a'), attributes: [[literal(...), 'x']]), as in Sequelize v6. Every value is sent as a bound parameter, never concatenated into the SQL text; arrays expand to a comma separated list of parameters.
cascadebooleanDROP TABLE ... CASCADE.

AlterOptions ​

alter options of sync().

ts
const alter: AlterOptions = { drop: false };
await sequelize.sync({ alter });
OptionTypeDescription
dropbooleanDrop columns that are not in the model. Default true.

TableOptions ​

Table options of @Table: the Model.init options without the sequelize instance.

ts
const options: TableOptions = { tableName: 'users', schema: 'app', paranoid: true, timestamps: true };
OptionTypeDescription
timestampsbooleanAdd createdAt / updatedAt. Default true.
underscoredbooleanUse snake_case column names for attributes and the table name.
freezeTableNamebooleanUse the model name as table name without pluralization.
schemastringPostgreSQL schema of the tables.
paranoidbooleanSoft-delete rows (deletedAt) instead of deleting them.
hooksPartial<Readonly<Record<"beforeValidate" | "afterValidate" | "validationFailed" | "befo…Hooks added to every model. Lifecycle hooks, by hook name.
modelNamestringModel name. Defaults to the class name.
nameReadonly<{ singular?: string | undefined; plural?: string | undefined; }>Singular and plural model name (Sequelize v6 ModelOptions.name). Drives the default alias and foreign key of belongsTo / hasOne / hasMany / belongsToMany and the accessor names. A missing form falls back to the inflection of modelName.
tableNamestringTable name. Defaults to the pluralized model name.
schemaDelimiterstringSeparator between schema and table that getTableName reports (PostgreSQL always uses . in SQL).
createdAtstring | booleanName of the created-at attribute, or false to disable it. Default: 'createdAt'.
updatedAtstring | booleanName of the updated-at attribute, or false to disable it. Default: 'updatedAt'.
deletedAtstring | booleanName of the deleted-at attribute of paranoid models. Default: 'deletedAt'.
versionstring | booleanOptimistic locking: true adds a version attribute, a string names it.
indexesreadonly Readonly<{ fields?: readonly IndexField[] | undefined; name?: string | undefin…Indexes created by sync().
commentstringTable comment.
unlogged postgrelize extensionbooleanCREATE UNLOGGED TABLE on sync: faster writes, no WAL, emptied after a crash, not replicated. PostgreSQL extension.
temporary postgrelize extensionbooleanCREATE TEMPORARY TABLE on sync: lives as long as the database session; cannot have a schema. See QueryInterface.createTable. PostgreSQL extension.
defaultScopeReadonly<Record<string, unknown>>Scope applied to every query unless unscoped() / scope() is used.
scopesReadonly<Record<string, ScopeDefinition>>Named scopes: options or functions returning options.
whereMergeStrategyWhereMergeStrategyHow where of merged scopes combine: 'overwrite' replaces same keys, 'and' joins them with Op.and. Default: 'overwrite'.
validateReadonly<Record<string, ModelValidatorFunction>>Model-level validators; throw to fail.
validationSchema postgrelize extensionReadonly<{ '~standard': Readonly<{ version: 1; vendor: string; validate: (value: unknow…Standard Schema (zod, valibot, arktype) validating all attribute values. postgrelize extension; schema keeps its v6 meaning (PostgreSQL schema).

ConstraintOptions ​

Options of addConstraint (Sequelize v6).

ts
const options: ConstraintOptions = {
  type: 'foreign key',
  fields: ['userId'],
  name: 'posts_user_fk',
  references: { table: 'users', field: 'id' },
  onDelete: 'CASCADE',
};
await queryInterface.addConstraint('posts', options);
OptionTypeDescription
type"unique" | "exclude" | "check" | "primary key" | "foreign key" | "CHECK" | "UNIQUE" | "…Constraint kind.
fieldsreadonly string[]Constrained columns. Not used by exclude (see exclude).
namestringConstraint name.
where{}Check condition, or the partial predicate of an exclude constraint (where object).
referencesReadonly<{ table: TableName; field: string; fields?: readonly string[] | undefined; }>Foreign key target.
onDeletestringON DELETE action.
onUpdatestringON UPDATE action.
deferrableReadonly<{ sql: string; }>Deferrable mode.
nullsNotDistinct postgrelize extensionbooleanNULLS NOT DISTINCT for unique constraints. PostgreSQL extension.
exclude postgrelize extensionreadonly ExcludeElement[]Exclusion elements: { column | expression, with }. Required by exclude. PostgreSQL extension.
usingstringIndex method of an exclude constraint (gist, spgist, btree, ...).
includereadonly string[]Covering columns of an exclude constraint (INCLUDE (...)).
withoutOverlaps postgrelize extensionbooleanLast field of a unique / primary key constraint is WITHOUT OVERLAPS (temporal key, PostgreSQL 18).
period postgrelize extensionbooleanLast field (and last referenced field) of a foreign key is PERIOD (PostgreSQL 18).
enforced postgrelize extensionbooleanfalse adds NOT ENFORCED (check and foreign key, PostgreSQL 18).
notValid postgrelize extensionbooleanAdds NOT VALID (check and foreign key only); run validateConstraint later. PostgreSQL extension.

IndexOptions ​

Options of addIndex and model indexes (Sequelize v6 IndexesOptions).

ts
const options: IndexOptions = {
  fields: ['email'],
  unique: true,
  where: { active: true },
  using: 'btree',
};
await queryInterface.addIndex('users', options);
OptionTypeDescription
fieldsreadonly IndexField[]Indexed columns.
namestringIndex name; default underscore(<table>_<fields>). Required when a field is an expression.
uniquebooleanUnique index.
nullsNotDistinct postgrelize extensionbooleanNULLS NOT DISTINCT for unique indexes. PostgreSQL extension.
usingstringIndex method: btree, hash, gist, gin, brin, ...
operatorstringDefault operator class for all fields.
where{}Partial index predicate.
concurrentlybooleanCREATE INDEX CONCURRENTLY.
includereadonly string[]Covering index columns (INCLUDE (...)).
ifNotExistsbooleanIF NOT EXISTS.

CreatePartitionOptions postgrelize extension ​

Options of createPartition. PostgreSQL extension.

ts
await queryInterface.createPartition(
  'events',
  'events_2026',
  { from: ['2026-01-01'], to: ['2027-01-01'] },
  { ifNotExists: true, partitionBy: { strategy: 'list', columns: ['kind'] } },
);
OptionTypeDescription
partitionByReadonly<{ strategy: PartitionStrategy; columns: readonly PartitionKeyElement[]; }>Makes the partition itself partitioned.
ifNotExistsbooleanIF NOT EXISTS.

DetachPartitionOptions postgrelize extension ​

Options of detachPartition. PostgreSQL extension.

ts
await queryInterface.detachPartition('events', 'events_2026', { concurrently: true });
OptionTypeDescription
concurrentlybooleanDETACH PARTITION ... CONCURRENTLY (cannot run inside a transaction).
finalizebooleanDETACH PARTITION ... FINALIZE, completing an interrupted concurrent detach.

CreateExtensionOptions postgrelize extension ​

Options of createExtension. PostgreSQL extension.

ts
const options: CreateExtensionOptions = { ifNotExists: true, schema: 'public' };
await queryInterface.createExtension('pg_trgm', options);
OptionTypeDescription
ifNotExistsbooleanAdds IF NOT EXISTS.
schemastringSchema that receives the extension objects.
versionstringExtension version to install.
cascadebooleanAlso installs the extensions it depends on.

DropExtensionOptions postgrelize extension ​

Options of dropExtension. PostgreSQL extension.

ts
const options: DropExtensionOptions = { ifExists: true, cascade: true };
await queryInterface.dropExtension('pg_trgm', options);
OptionTypeDescription
ifExistsbooleanAdds IF EXISTS.
cascadebooleanAlso drops objects that depend on the extension.

CreateSequenceOptions postgrelize extension ​

Options of createSequence. PostgreSQL extension.

ts
const options: CreateSequenceOptions = { dataType: 'bigint', start: 1000, cache: 10 };
await queryInterface.createSequence('invoice_number', options);
OptionTypeDescription
dataType"bigint" | "smallint" | "integer"AS smallint | integer | bigint.
startSequenceNumberSTART WITH.
incrementSequenceNumberINCREMENT BY.
minValuefalse | SequenceNumberMINVALUE; false renders NO MINVALUE.
maxValuefalse | SequenceNumberMAXVALUE; false renders NO MAXVALUE.
cacheSequenceNumberCACHE.
cyclebooleanCYCLE / NO CYCLE.
ownedByReadonly<{ table: TableName; column: string; }>OWNED BY table.column; null renders OWNED BY NONE.
ifNotExistsbooleanAdds IF NOT EXISTS.

AlterSequenceOptions postgrelize extension ​

Options of alterSequence. PostgreSQL extension.

ts
const options: AlterSequenceOptions = { restartWith: 1, cycle: true };
await queryInterface.alterSequence('invoice_number', options);
OptionTypeDescription
incrementSequenceNumberINCREMENT BY.
minValuefalse | SequenceNumberMINVALUE; false renders NO MINVALUE.
maxValuefalse | SequenceNumberMAXVALUE; false renders NO MAXVALUE.
cacheSequenceNumberCACHE.
cyclebooleanCYCLE / NO CYCLE.
ownedByReadonly<{ table: TableName; column: string; }>OWNED BY table.column; null renders OWNED BY NONE.
restartWithtrue | SequenceNumberRESTART WITH n; true renders a bare RESTART (back to the start value).
ifExistsbooleanAdds IF EXISTS.

DropSequenceOptions postgrelize extension ​

Options of dropSequence. PostgreSQL extension.

ts
const options: DropSequenceOptions = { ifExists: true };
await queryInterface.dropSequence('invoice_number', options);
OptionTypeDescription
ifExistsbooleanAdds IF EXISTS.
cascadebooleanAlso drops objects that depend on the sequence.

CreateFunctionOptions ​

Options of createFunction.

ts
const options: CreateFunctionOptions = {
  force: true,
  variables: [{ name: 'limit_rows', type: 'integer', default: 100 }],
};
await queryInterface.createFunction('f', [], 'integer', 'plpgsql', 'RETURN limit_rows;', [], options);
OptionTypeDescription
variablesreadonly Readonly<{ name: string; type: string; default?: unknown; }>[]Local variables (DECLARE name type := default;).
forcebooleanCREATE OR REPLACE FUNCTION.

DropFunctionOptions ​

Options of dropFunction.

ts
const options: DropFunctionOptions = { ifExists: true, cascade: true };
await queryInterface.dropFunction('f', [], options);
OptionTypeDescription
ifExistsbooleanAdds IF EXISTS.
cascadebooleanCASCADE instead of the default RESTRICT.

CreateTriggerOptions ​

Options of createTrigger.

ts
const options: CreateTriggerOptions = { replace: true };
await queryInterface.createTrigger('Posts', 'posts_touch', 'before', ['update'], 'touch', [], [], options);
OptionTypeDescription
replacebooleanCREATE OR REPLACE TRIGGER (PostgreSQL 14+).

DropTriggerOptions ​

Options of dropTrigger.

ts
const options: DropTriggerOptions = { ifExists: true };
await queryInterface.dropTrigger('Posts', 'posts_touch', options);
OptionTypeDescription
ifExistsbooleanAdds IF EXISTS.
cascadebooleanCASCADE instead of the default RESTRICT.

CreateViewOptions postgrelize extension ​

Options of createView. PostgreSQL extension.

ts
const options: CreateViewOptions = { replace: true, columns: ['id', 'title'], checkOption: 'local' };
await queryInterface.createView('published_posts', 'SELECT id, title FROM "Posts" WHERE published', options);
OptionTypeDescription
replacebooleanCREATE OR REPLACE VIEW.
temporarybooleanCREATE TEMPORARY VIEW: lives as long as the database session (pooled connection).
recursivebooleanCREATE RECURSIVE VIEW; needs columns.
columnsreadonly string[]Output column names.
checkOption"local" | "cascaded"WITH LOCAL | CASCADED CHECK OPTION for updatable views.
securityBarrierbooleansecurity_barrier view option.
securityInvokerbooleansecurity_invoker view option (queries run with the privileges of the caller).

DropViewOptions postgrelize extension ​

Options of dropView and dropMaterializedView. PostgreSQL extension.

ts
const options: DropViewOptions = { ifExists: true, cascade: true };
await queryInterface.dropView('published_posts', options);
OptionTypeDescription
ifExistsbooleanAdds IF EXISTS.
cascadebooleanAlso drops objects that depend on the view.

CreateMaterializedViewOptions postgrelize extension ​

Options of createMaterializedView. PostgreSQL extension.

ts
const options: CreateMaterializedViewOptions = { ifNotExists: true, withData: false };
await queryInterface.createMaterializedView('post_stats', 'SELECT count(*) AS n FROM "Posts"', options);
OptionTypeDescription
ifNotExistsbooleanAdds IF NOT EXISTS.
columnsreadonly string[]Output column names.
usingstringTable access method (USING heap).
withDatabooleanfalse renders WITH NO DATA: the view is created empty and unreadable until refreshed.

RefreshMaterializedViewOptions postgrelize extension ​

Options of refreshMaterializedView. PostgreSQL extension.

ts
const options: RefreshMaterializedViewOptions = { concurrently: true };
await queryInterface.refreshMaterializedView('post_stats', options);
OptionTypeDescription
concurrentlybooleanREFRESH ... CONCURRENTLY: readers are not blocked; needs a unique index and cannot be combined with withData: false.
withDatabooleanfalse renders WITH NO DATA (empties the view).

CreatePolicyOptions postgrelize extension ​

Options of createPolicy. PostgreSQL extension.

ts
const options: CreatePolicyOptions = {
  command: 'select',
  roles: ['app_user'],
  using: "tenant_id = current_setting('app.tenant_id')::int",
};
await queryInterface.createPolicy('documents', 'tenant_isolation', options);
OptionTypeDescription
command"all" | "insert" | "update" | "delete" | "select"Command the policy applies to; defaults to 'all'.
kind"permissive" | "restrictive"'permissive' (default) or 'restrictive'.
rolesreadonly string[]Roles the policy applies to: role names, or 'public', 'current_user', 'current_role', 'session_user'.
usingPolicyConditionUSING (...): which existing rows are visible. SQL text is trusted; a where object is compiled with literals.
withCheckPolicyConditionWITH CHECK (...): which new rows may be written. Same forms as using.

AlterPolicyOptions postgrelize extension ​

Options of alterPolicy. PostgreSQL extension.

ts
const options: AlterPolicyOptions = { roles: ['app_user', 'app_admin'], rename: 'tenant_rows' };
await queryInterface.alterPolicy('documents', 'tenant_isolation', options);
OptionTypeDescription
rolesreadonly string[]Roles the policy applies to: role names, or 'public', 'current_user', 'current_role', 'session_user'.
usingPolicyConditionUSING (...): which existing rows are visible. SQL text is trusted; a where object is compiled with literals.
withCheckPolicyConditionWITH CHECK (...): which new rows may be written. Same forms as using.
renamestringNew policy name (applied after the other changes).

DropPolicyOptions postgrelize extension ​

Options of dropPolicy. PostgreSQL extension.

ts
const options: DropPolicyOptions = { ifExists: true };
await queryInterface.dropPolicy('documents', 'tenant_isolation', options);
OptionTypeDescription
ifExistsbooleanAdds IF EXISTS.
cascadebooleanAlso drops objects that depend on the policy.

EnableRowLevelSecurityOptions postgrelize extension ​

Options of enableRowLevelSecurity. PostgreSQL extension.

ts
const options: EnableRowLevelSecurityOptions = { force: true };
await queryInterface.enableRowLevelSecurity('documents', options);
OptionTypeDescription
forcebooleanAlso FORCE ROW LEVEL SECURITY: the table owner is subject to the policies too.

DisableRowLevelSecurityOptions postgrelize extension ​

Options of disableRowLevelSecurity. PostgreSQL extension.

ts
const options: DisableRowLevelSecurityOptions = { noForce: true };
await queryInterface.disableRowLevelSecurity('documents', options);
OptionTypeDescription
noForcebooleanAlso NO FORCE ROW LEVEL SECURITY.

Released under the MIT License.