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.
CreateTableOptionsDropTableOptionsAlterOptionsTableOptionsConstraintOptionsIndexOptionsCreatePartitionOptionsDetachPartitionOptionsCreateExtensionOptionsDropExtensionOptionsCreateSequenceOptionsAlterSequenceOptionsDropSequenceOptionsCreateFunctionOptionsDropFunctionOptionsCreateTriggerOptionsDropTriggerOptionsCreateViewOptionsDropViewOptionsCreateMaterializedViewOptionsRefreshMaterializedViewOptionsCreatePolicyOptionsAlterPolicyOptionsDropPolicyOptionsEnableRowLevelSecurityOptionsDisableRowLevelSecurityOptions
CreateTableOptions
Options of createTable: a table comment, the table persistence and the common query options.
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'] } });| Option | Type | Description |
|---|---|---|
transaction | Transaction | Transaction to run in; null forces running outside the CLS transaction. |
logging | false | LoggingFunction | SQL logger for this query, or false. |
benchmark | boolean | Pass query duration to the logger. |
statementTimeout postgrelize extension | number | statement_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. |
retry | Readonly<{ 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 extension | boolean | Force the writer even for SELECTs when read replicas are configured. postgrelize extension. |
replacements | Replacements | Values 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. |
comment | string | Table comment. |
unlogged | boolean | CREATE UNLOGGED TABLE: not written to the WAL, faster writes, emptied after a crash and not replicated. |
temporary | boolean | CREATE 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. |
partitionBy | Readonly<{ 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.
const options: DropTableOptions = { cascade: true };
await queryInterface.dropTable('posts', options);| Option | Type | Description |
|---|---|---|
transaction | Transaction | Transaction to run in; null forces running outside the CLS transaction. |
logging | false | LoggingFunction | SQL logger for this query, or false. |
benchmark | boolean | Pass query duration to the logger. |
statementTimeout postgrelize extension | number | statement_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. |
retry | Readonly<{ 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 extension | boolean | Force the writer even for SELECTs when read replicas are configured. postgrelize extension. |
replacements | Replacements | Values 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. |
cascade | boolean | DROP TABLE ... CASCADE. |
AlterOptions
alter options of sync().
const alter: AlterOptions = { drop: false };
await sequelize.sync({ alter });| Option | Type | Description |
|---|---|---|
drop | boolean | Drop columns that are not in the model. Default true. |
TableOptions
Table options of @Table: the Model.init options without the sequelize instance.
const options: TableOptions = { tableName: 'users', schema: 'app', paranoid: true, timestamps: true };| Option | Type | Description |
|---|---|---|
timestamps | boolean | Add createdAt / updatedAt. Default true. |
underscored | boolean | Use snake_case column names for attributes and the table name. |
freezeTableName | boolean | Use the model name as table name without pluralization. |
schema | string | PostgreSQL schema of the tables. |
paranoid | boolean | Soft-delete rows (deletedAt) instead of deleting them. |
hooks | Partial<Readonly<Record<"beforeValidate" | "afterValidate" | "validationFailed" | "befo… | Hooks added to every model. Lifecycle hooks, by hook name. |
modelName | string | Model name. Defaults to the class name. |
name | Readonly<{ 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. |
tableName | string | Table name. Defaults to the pluralized model name. |
schemaDelimiter | string | Separator between schema and table that getTableName reports (PostgreSQL always uses . in SQL). |
createdAt | string | boolean | Name of the created-at attribute, or false to disable it. Default: 'createdAt'. |
updatedAt | string | boolean | Name of the updated-at attribute, or false to disable it. Default: 'updatedAt'. |
deletedAt | string | boolean | Name of the deleted-at attribute of paranoid models. Default: 'deletedAt'. |
version | string | boolean | Optimistic locking: true adds a version attribute, a string names it. |
indexes | readonly Readonly<{ fields?: readonly IndexField[] | undefined; name?: string | undefin… | Indexes created by sync(). |
comment | string | Table comment. |
unlogged postgrelize extension | boolean | CREATE UNLOGGED TABLE on sync: faster writes, no WAL, emptied after a crash, not replicated. PostgreSQL extension. |
temporary postgrelize extension | boolean | CREATE TEMPORARY TABLE on sync: lives as long as the database session; cannot have a schema. See QueryInterface.createTable. PostgreSQL extension. |
defaultScope | Readonly<Record<string, unknown>> | Scope applied to every query unless unscoped() / scope() is used. |
scopes | Readonly<Record<string, ScopeDefinition>> | Named scopes: options or functions returning options. |
whereMergeStrategy | WhereMergeStrategy | How where of merged scopes combine: 'overwrite' replaces same keys, 'and' joins them with Op.and. Default: 'overwrite'. |
validate | Readonly<Record<string, ModelValidatorFunction>> | Model-level validators; throw to fail. |
validationSchema postgrelize extension | Readonly<{ '~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).
const options: ConstraintOptions = {
type: 'foreign key',
fields: ['userId'],
name: 'posts_user_fk',
references: { table: 'users', field: 'id' },
onDelete: 'CASCADE',
};
await queryInterface.addConstraint('posts', options);| Option | Type | Description |
|---|---|---|
type | "unique" | "exclude" | "check" | "primary key" | "foreign key" | "CHECK" | "UNIQUE" | "… | Constraint kind. |
fields | readonly string[] | Constrained columns. Not used by exclude (see exclude). |
name | string | Constraint name. |
where | {} | Check condition, or the partial predicate of an exclude constraint (where object). |
references | Readonly<{ table: TableName; field: string; fields?: readonly string[] | undefined; }> | Foreign key target. |
onDelete | string | ON DELETE action. |
onUpdate | string | ON UPDATE action. |
deferrable | Readonly<{ sql: string; }> | Deferrable mode. |
nullsNotDistinct postgrelize extension | boolean | NULLS NOT DISTINCT for unique constraints. PostgreSQL extension. |
exclude postgrelize extension | readonly ExcludeElement[] | Exclusion elements: { column | expression, with }. Required by exclude. PostgreSQL extension. |
using | string | Index method of an exclude constraint (gist, spgist, btree, ...). |
include | readonly string[] | Covering columns of an exclude constraint (INCLUDE (...)). |
withoutOverlaps postgrelize extension | boolean | Last field of a unique / primary key constraint is WITHOUT OVERLAPS (temporal key, PostgreSQL 18). |
period postgrelize extension | boolean | Last field (and last referenced field) of a foreign key is PERIOD (PostgreSQL 18). |
enforced postgrelize extension | boolean | false adds NOT ENFORCED (check and foreign key, PostgreSQL 18). |
notValid postgrelize extension | boolean | Adds NOT VALID (check and foreign key only); run validateConstraint later. PostgreSQL extension. |
IndexOptions
Options of addIndex and model indexes (Sequelize v6 IndexesOptions).
const options: IndexOptions = {
fields: ['email'],
unique: true,
where: { active: true },
using: 'btree',
};
await queryInterface.addIndex('users', options);| Option | Type | Description |
|---|---|---|
fields | readonly IndexField[] | Indexed columns. |
name | string | Index name; default underscore(<table>_<fields>). Required when a field is an expression. |
unique | boolean | Unique index. |
nullsNotDistinct postgrelize extension | boolean | NULLS NOT DISTINCT for unique indexes. PostgreSQL extension. |
using | string | Index method: btree, hash, gist, gin, brin, ... |
operator | string | Default operator class for all fields. |
where | {} | Partial index predicate. |
concurrently | boolean | CREATE INDEX CONCURRENTLY. |
include | readonly string[] | Covering index columns (INCLUDE (...)). |
ifNotExists | boolean | IF NOT EXISTS. |
CreatePartitionOptions postgrelize extension
Options of createPartition. PostgreSQL extension.
await queryInterface.createPartition(
'events',
'events_2026',
{ from: ['2026-01-01'], to: ['2027-01-01'] },
{ ifNotExists: true, partitionBy: { strategy: 'list', columns: ['kind'] } },
);| Option | Type | Description |
|---|---|---|
partitionBy | Readonly<{ strategy: PartitionStrategy; columns: readonly PartitionKeyElement[]; }> | Makes the partition itself partitioned. |
ifNotExists | boolean | IF NOT EXISTS. |
DetachPartitionOptions postgrelize extension
Options of detachPartition. PostgreSQL extension.
await queryInterface.detachPartition('events', 'events_2026', { concurrently: true });| Option | Type | Description |
|---|---|---|
concurrently | boolean | DETACH PARTITION ... CONCURRENTLY (cannot run inside a transaction). |
finalize | boolean | DETACH PARTITION ... FINALIZE, completing an interrupted concurrent detach. |
CreateExtensionOptions postgrelize extension
Options of createExtension. PostgreSQL extension.
const options: CreateExtensionOptions = { ifNotExists: true, schema: 'public' };
await queryInterface.createExtension('pg_trgm', options);| Option | Type | Description |
|---|---|---|
ifNotExists | boolean | Adds IF NOT EXISTS. |
schema | string | Schema that receives the extension objects. |
version | string | Extension version to install. |
cascade | boolean | Also installs the extensions it depends on. |
DropExtensionOptions postgrelize extension
Options of dropExtension. PostgreSQL extension.
const options: DropExtensionOptions = { ifExists: true, cascade: true };
await queryInterface.dropExtension('pg_trgm', options);| Option | Type | Description |
|---|---|---|
ifExists | boolean | Adds IF EXISTS. |
cascade | boolean | Also drops objects that depend on the extension. |
CreateSequenceOptions postgrelize extension
Options of createSequence. PostgreSQL extension.
const options: CreateSequenceOptions = { dataType: 'bigint', start: 1000, cache: 10 };
await queryInterface.createSequence('invoice_number', options);| Option | Type | Description |
|---|---|---|
dataType | "bigint" | "smallint" | "integer" | AS smallint | integer | bigint. |
start | SequenceNumber | START WITH. |
increment | SequenceNumber | INCREMENT BY. |
minValue | false | SequenceNumber | MINVALUE; false renders NO MINVALUE. |
maxValue | false | SequenceNumber | MAXVALUE; false renders NO MAXVALUE. |
cache | SequenceNumber | CACHE. |
cycle | boolean | CYCLE / NO CYCLE. |
ownedBy | Readonly<{ table: TableName; column: string; }> | OWNED BY table.column; null renders OWNED BY NONE. |
ifNotExists | boolean | Adds IF NOT EXISTS. |
AlterSequenceOptions postgrelize extension
Options of alterSequence. PostgreSQL extension.
const options: AlterSequenceOptions = { restartWith: 1, cycle: true };
await queryInterface.alterSequence('invoice_number', options);| Option | Type | Description |
|---|---|---|
increment | SequenceNumber | INCREMENT BY. |
minValue | false | SequenceNumber | MINVALUE; false renders NO MINVALUE. |
maxValue | false | SequenceNumber | MAXVALUE; false renders NO MAXVALUE. |
cache | SequenceNumber | CACHE. |
cycle | boolean | CYCLE / NO CYCLE. |
ownedBy | Readonly<{ table: TableName; column: string; }> | OWNED BY table.column; null renders OWNED BY NONE. |
restartWith | true | SequenceNumber | RESTART WITH n; true renders a bare RESTART (back to the start value). |
ifExists | boolean | Adds IF EXISTS. |
DropSequenceOptions postgrelize extension
Options of dropSequence. PostgreSQL extension.
const options: DropSequenceOptions = { ifExists: true };
await queryInterface.dropSequence('invoice_number', options);| Option | Type | Description |
|---|---|---|
ifExists | boolean | Adds IF EXISTS. |
cascade | boolean | Also drops objects that depend on the sequence. |
CreateFunctionOptions
Options of createFunction.
const options: CreateFunctionOptions = {
force: true,
variables: [{ name: 'limit_rows', type: 'integer', default: 100 }],
};
await queryInterface.createFunction('f', [], 'integer', 'plpgsql', 'RETURN limit_rows;', [], options);| Option | Type | Description |
|---|---|---|
variables | readonly Readonly<{ name: string; type: string; default?: unknown; }>[] | Local variables (DECLARE name type := default;). |
force | boolean | CREATE OR REPLACE FUNCTION. |
DropFunctionOptions
Options of dropFunction.
const options: DropFunctionOptions = { ifExists: true, cascade: true };
await queryInterface.dropFunction('f', [], options);| Option | Type | Description |
|---|---|---|
ifExists | boolean | Adds IF EXISTS. |
cascade | boolean | CASCADE instead of the default RESTRICT. |
CreateTriggerOptions
Options of createTrigger.
const options: CreateTriggerOptions = { replace: true };
await queryInterface.createTrigger('Posts', 'posts_touch', 'before', ['update'], 'touch', [], [], options);| Option | Type | Description |
|---|---|---|
replace | boolean | CREATE OR REPLACE TRIGGER (PostgreSQL 14+). |
DropTriggerOptions
Options of dropTrigger.
const options: DropTriggerOptions = { ifExists: true };
await queryInterface.dropTrigger('Posts', 'posts_touch', options);| Option | Type | Description |
|---|---|---|
ifExists | boolean | Adds IF EXISTS. |
cascade | boolean | CASCADE instead of the default RESTRICT. |
CreateViewOptions postgrelize extension
Options of createView. PostgreSQL extension.
const options: CreateViewOptions = { replace: true, columns: ['id', 'title'], checkOption: 'local' };
await queryInterface.createView('published_posts', 'SELECT id, title FROM "Posts" WHERE published', options);| Option | Type | Description |
|---|---|---|
replace | boolean | CREATE OR REPLACE VIEW. |
temporary | boolean | CREATE TEMPORARY VIEW: lives as long as the database session (pooled connection). |
recursive | boolean | CREATE RECURSIVE VIEW; needs columns. |
columns | readonly string[] | Output column names. |
checkOption | "local" | "cascaded" | WITH LOCAL | CASCADED CHECK OPTION for updatable views. |
securityBarrier | boolean | security_barrier view option. |
securityInvoker | boolean | security_invoker view option (queries run with the privileges of the caller). |
DropViewOptions postgrelize extension
Options of dropView and dropMaterializedView. PostgreSQL extension.
const options: DropViewOptions = { ifExists: true, cascade: true };
await queryInterface.dropView('published_posts', options);| Option | Type | Description |
|---|---|---|
ifExists | boolean | Adds IF EXISTS. |
cascade | boolean | Also drops objects that depend on the view. |
CreateMaterializedViewOptions postgrelize extension
Options of createMaterializedView. PostgreSQL extension.
const options: CreateMaterializedViewOptions = { ifNotExists: true, withData: false };
await queryInterface.createMaterializedView('post_stats', 'SELECT count(*) AS n FROM "Posts"', options);| Option | Type | Description |
|---|---|---|
ifNotExists | boolean | Adds IF NOT EXISTS. |
columns | readonly string[] | Output column names. |
using | string | Table access method (USING heap). |
withData | boolean | false renders WITH NO DATA: the view is created empty and unreadable until refreshed. |
RefreshMaterializedViewOptions postgrelize extension
Options of refreshMaterializedView. PostgreSQL extension.
const options: RefreshMaterializedViewOptions = { concurrently: true };
await queryInterface.refreshMaterializedView('post_stats', options);| Option | Type | Description |
|---|---|---|
concurrently | boolean | REFRESH ... CONCURRENTLY: readers are not blocked; needs a unique index and cannot be combined with withData: false. |
withData | boolean | false renders WITH NO DATA (empties the view). |
CreatePolicyOptions postgrelize extension
Options of createPolicy. PostgreSQL extension.
const options: CreatePolicyOptions = {
command: 'select',
roles: ['app_user'],
using: "tenant_id = current_setting('app.tenant_id')::int",
};
await queryInterface.createPolicy('documents', 'tenant_isolation', options);| Option | Type | Description |
|---|---|---|
command | "all" | "insert" | "update" | "delete" | "select" | Command the policy applies to; defaults to 'all'. |
kind | "permissive" | "restrictive" | 'permissive' (default) or 'restrictive'. |
roles | readonly string[] | Roles the policy applies to: role names, or 'public', 'current_user', 'current_role', 'session_user'. |
using | PolicyCondition | USING (...): which existing rows are visible. SQL text is trusted; a where object is compiled with literals. |
withCheck | PolicyCondition | WITH CHECK (...): which new rows may be written. Same forms as using. |
AlterPolicyOptions postgrelize extension
Options of alterPolicy. PostgreSQL extension.
const options: AlterPolicyOptions = { roles: ['app_user', 'app_admin'], rename: 'tenant_rows' };
await queryInterface.alterPolicy('documents', 'tenant_isolation', options);| Option | Type | Description |
|---|---|---|
roles | readonly string[] | Roles the policy applies to: role names, or 'public', 'current_user', 'current_role', 'session_user'. |
using | PolicyCondition | USING (...): which existing rows are visible. SQL text is trusted; a where object is compiled with literals. |
withCheck | PolicyCondition | WITH CHECK (...): which new rows may be written. Same forms as using. |
rename | string | New policy name (applied after the other changes). |
DropPolicyOptions postgrelize extension
Options of dropPolicy. PostgreSQL extension.
const options: DropPolicyOptions = { ifExists: true };
await queryInterface.dropPolicy('documents', 'tenant_isolation', options);| Option | Type | Description |
|---|---|---|
ifExists | boolean | Adds IF EXISTS. |
cascade | boolean | Also drops objects that depend on the policy. |
EnableRowLevelSecurityOptions postgrelize extension
Options of enableRowLevelSecurity. PostgreSQL extension.
const options: EnableRowLevelSecurityOptions = { force: true };
await queryInterface.enableRowLevelSecurity('documents', options);| Option | Type | Description |
|---|---|---|
force | boolean | Also FORCE ROW LEVEL SECURITY: the table owner is subject to the policies too. |
DisableRowLevelSecurityOptions postgrelize extension
Options of disableRowLevelSecurity. PostgreSQL extension.
const options: DisableRowLevelSecurityOptions = { noForce: true };
await queryInterface.disableRowLevelSecurity('documents', options);| Option | Type | Description |
|---|---|---|
noForce | boolean | Also NO FORCE ROW LEVEL SECURITY. |