Documentation

Docs / Reference

Claim contract: Sequelize models

The environment assumptions and claim contract of the Sequelize model extractor (ADR 0061) as recorded when it was designed (task T018g3, internal record). docs/extract/schema-sequelize.md and the code table in internal/extract/models/sequelize must equal them (TestSequelizeContract).

Environment (assumptions, part of the contract)

Claim contract

Finalised from the inventory and the oracle (the investigation). Row kinds: K scope and naming; M model forms; A attributes; O model options; R associations; P provable failures; U unread tool folders; V assumptions; D the single default branch. Every form the corpora use has exactly one row (counts per row: the T018g3 inventory (internal record)); forms only the fixture uses come from the same oracle runs (scratch probes). The contract test keeps docs/extract/schema-sequelize.md, the Go table and the code 1:1 (plan, shared piece 4). 15 rows: 14 rows plus D; SQ-P1 only refuses, SQ-U1 only marks, SQ-V has no branch.

Dialect rule (developer decision 2026-11-13):

Provider-independent facts (table and column names, column set, primary key columns, foreign-key target table and columns) are claimed for every supported dialect with the dialect's verification.

id form claim refusal / unknown assumptions
SQ-K1 scope (Discovery above): package dependency on sequelize 6.x, lockfile pins, the module-level new Sequelize(...) instance, its literal dialect or the single-driver rule, literal define/schema options, model reach (an imported instance binding as init's sequelize option or define receiver; a factory's first parameter called with the instance through a relative require), association reach (module level; the recognised associate(models) loop; Revision 3, the sequelize-cli loop: Object.keys(M).forEach, Object.values(M).forEach or for...of over Object.keys(M) / Object.values(M) whose body is R.associate && R.associate(M) or if (R.associate) R.associate(M), an init class's static associate(models), a models object entry that is a require(...)(...) factory call, and models object assignments M.X = ... before the loop), the options require(config)[env] (open point O2's rule: read when every entry agrees) the group (models/sequelize/<instance file>), its model set, dialect, pins, the global define options another major: marker, no claims; dialect unknown (no or several drivers, non-literal without a driver rule): dialect-dependent facts unknown; constructor options with a spread or a non-literal define: SQ-V5 per open point O1, else every option-derived fact unknown; instance hooks: D; a model whose receiver does not resolve, or that reaches two instances: not claimed (marker); directory loaders: D SQ-V1, SQ-V4, SQ-V5
SQ-K2 naming: model name (define's literal first argument; init's modelName option, else the class name); table name: tableName literal, else the model name when freezeTableName, else inflection.pluralize(name) (1.13.4), passed through inflection.underscore when underscored (lib/model.js:705-709); schema option (postgres); column name: the attribute's literal field, else the attribute key, passed through inflection.underscore when underscored (lib/model.js:838-840) table name and schema, column names (Person -> People, Mouse -> Mice, Archived -> Archiveds, BlogPost underscored -> blog_posts; freeze ignores underscored) a non-literal model name, tableName, field, freezeTableName or underscored: the names derived from it unknown (table or column not claimed); schema on sqlite/mysql: unknown SQ-V1
SQ-M1 <instance>.define("Name", {attributes}, {options}?) at module level of a reached module, or as a statement of a reached factory's body; option keys with no table fact: hooks, scopes, defaultScope, validate, getterMethods, setterMethods a model (table) non-literal name, attributes or options object: D; define in any other function (opencollective-api Temporal): D (marker naming it; the group's table_list is may_be_incomplete) SQ-V2, SQ-V3
SQ-M2 class X extends Model (from sequelize, or a class of a reached module whose chain ends in Model, e.g. ModelWithPublicId) with exactly one unconditional module-level statement X.init({attributes}, {sequelize, ...options}); same no-fact option keys as SQ-M1 a model named by modelName or the class name more than one init site, init in a function or a condition, a class chain not ending in Sequelize's Model: D; a later X.removeAttribute(...) or rawAttributes mutation: the table is partial (column set and primary key unknown) SQ-V2, SQ-V3
SQ-A1 attribute type: {type: DataTypes.X(args)} or the shorthand key: DataTypes.X (DataTypes or Sequelize from sequelize, the factory's second parameter, or a re-export of either), from a closed per-dialect list the oracle has run (the investigation: STRING, STRING(n), CHAR(n), TEXT, INTEGER, BIGINT, SMALLINT, FLOAT, DOUBLE, DECIMAL, DECIMAL(p, s), BOOLEAN, DATE, DATEONLY, TIME, UUID, JSON, JSONB (postgres), BLOB, ENUM(...) / {type: ENUM, values}, ARRAY(T) and RANGE(DATE) (postgres)); VIRTUAL; the helper member (Revision 2, open point O4): an attribute value H(args).member or H(args), H an identifier resolving (module resolver, CommonJS reach) to a module-level function (a function declaration, plain, export or export default; export default F; module.exports = F or exports.<name> = F; F a non-async, non-generator function or arrow) whose body is a single return of an object literal, member (or the whole object) a plain property that no later entry can override, read as the attribute value this row and SQ-A2 read once each parameter is replaced by the call's own argument (DataTypes or Sequelize as above, used only as <p>.X, or a string, number, boolean or null literal; one argument per parameter) column type as the catalog shows it: postgres character varying(255), timestamp with time zone, double precision (FLOAT and DOUBLE), numeric(p,s), bytea, enum_<table>_<column> (quoted when not lower case) and [] for arrays, tstzrange; sqlite VARCHAR(255), DATETIME, TINYINT(1), DOUBLE PRECISION, TEXT for ENUM, UUID, JSON; enum labels in order when every value is a string literal; VIRTUAL: no column; a helper member (CustomDataTypes(DataTypes).currency): the facts of the substituted value, with its verification a type outside the list, a project class (new X() of DataTypes.ABSTRACT subclasses), any other helper result (a body other than one return of an object literal, a member a spread or later entry can override, a computed member, a parameter used other than as the DataTypes namespace, an argument that is neither DataTypes nor a literal, a function bound by const, an async or generator function; a name the helper's module binds is not resolved, so a fact that needs it is unknown), a string type (raw SQL), a new DataTypes.X(...) form: the column itself unknown (an unread type could be VIRTUAL), table column set not complete; non-literal ENUM values: type claimed (the enum type name), labels unknown SQ-V1, SQ-V3
SQ-A2 column facts of a literal attribute object: allowNull, primaryKey, autoIncrement, unique (true, a literal group name, {name}), defaultValue, index: true on JSONB; keys with no table fact: validate, get, set, comment nullability: postgres not null when allowNull: false or a primary key; sqlite (dialects/sqlite/query-generator.js:36-75) a single primary key whose type contains INT becomes INTEGER PRIMARY KEY (nullable in the catalog, type INTEGER), composite primary-key members are not null, any other column only with allowNull: false; primary key columns; autoIncrement on postgres: SERIAL/BIGSERIAL (integer, nextval default); unique: single-column unique, or composite unique over the columns sharing a group name (the group name is not the constraint name); default: string, number, boolean literal (sqlite booleans 1/0), null as no default, any literal on JSON/JSONB as JSON.stringify text, sequelize.literal("...") / fn(...): a database default is present (its text is not claimed: Postgres re-renders it, and the oracle compared presence only); NOW, UUIDV4, UUIDV1: no database default; index: true on JSONB: a gin index named underscore("<table>_<column>") (lib/model.js:883-889) a non-literal value: that fact unknown; an enum-member default (X.PENDING, open point O5): default unknown; fn(...) default on sqlite: SQ-P1; constraint names: never claimed SQ-V2
SQ-A3 attribute references: {model: "table" or a reached model class, key} with onDelete / onUpdate foreign key to that table and column (key absent: id), actions as written upper-cased, else NO ACTION (the database default; Sequelize writes no clause); on mssql (Revision 3) the actions its attributesToSQL keeps: the first references to a table loses onUpdate, a later one to the same table and a self-reference lose both (NO ACTION; dialects/mssql/query-generator.js:488-494, :542-561) non-literal model or key: foreign key unknown (table partial); postgres in a cyclic group: a foreign key on a primary-key column unknown, every foreign key of a model with an alter-failing attribute (ARRAY(ENUM); a literal/fn default together with unique: true) unknown; also unknown (accepted in Revision 2, no claim change): in that cyclic rule a plain default with unique: true, a default with references, a SERIAL column that is not the primary key and a column that is not read are alter-failing, and a group that may be cyclic (a model, attribute, association or join table not read, a definition marker) is treated as cyclic; on mysql, mariadb and mssql every foreign key of a cyclic or possibly cyclic group; a foreign key to a target whose primary key may be composite (an attribute not read); a composite-key target: no foreign key (the attribute only, []); a referenced column not proven to be the target's only primary-key column or a unique column: foreign key unknown (provably neither: SQ-P1); on mssql a reference after an attribute whose references target is not read: foreign key unknown (R3-A1) SQ-V2
SQ-O1 default attributes: implicit id (INTEGER, primary key, auto increment) when no attribute is a primary key, prepended; timestamps (default true) with createdAt / updatedAt / deletedAt (string or false), paranoid, version (lib/model.js:188-239) the id, createdAt, updatedAt (DATE, not null), deletedAt (DATE, nullable, with paranoid), version (INTEGER not null default 0) columns, names through SQ-K2; a user attribute of the same name wins entirely non-literal timestamps/paranoid/timestamp names: those columns unknown; an incomplete attribute set (spread, unread entry): implicit id unknown SQ-V5
SQ-O2 option indexes: [{fields, unique, name, using, where}] with literal string fields or {name, order} objects index name (omitted: inflection.underscore("<table>_<fields>"), lib/utils.js:413-421), columns, unique, method (using), partial (where present) a non-literal element or field: that index unknown (table partial); predicate text: unknown (not compared) SQ-V2
SQ-R1 A.belongsTo(B, opts), A.hasOne(B, opts), A.hasMany(B, opts) with literal options (foreignKey string or {name, allowNull, field}, as, targetKey/sourceKey, onDelete, onUpdate, constraints; scope has no table fact), in reach order the foreign-key attribute on the holder (belongsTo: source; hasOne/hasMany: target): name foreignKey, else camelize(as or B's singular + "_" + B's key) (belongsTo), camelize(A's singular + "_" + A's key) (hasMany), camelize(singularize(as or A's name) + "_" + A's key) (hasOne uses as); a new attribute has the key's type and is nullable; merged into an existing attribute without overriding any value it already has, first association first; unless constraints: false, a foreign key with onDelete as written, else belongsTo SET NULL only when the attribute's allowNull is truthy and NO ACTION otherwise (an omitted allowNull gives NO ACTION on a nullable column), hasOne/hasMany SET NULL or CASCADE likewise; onUpdate as written, else CASCADE (associations/belongs-to.js:77-80, has-many.js:103-106, has-one.js:78-81); on mssql the actions as SQ-A3 states non-literal options or targets, associations outside the reach rule: the facts they may add unknown (holder's column set not complete); constraints: false keeps an attribute's own references; a cross-schema association on postgres: SQ-P1; postgres cyclic group: as SQ-A3; a targetKey / sourceKey not proven unique: as SQ-A3 SQ-V2
SQ-R2 A.belongsToMany(B, {through: "table", foreignKey?, otherKey?}) with a string through, A not B, and no other belongsToMany over the same through a join table named through: createdAt/updatedAt first (from the source's timestamps), then the two keys (camelize(singular + "_" + key) unless given), both not null, together the primary key, each a foreign key CASCADE/CASCADE to its model (associations/belongs-to-many.js:186-247) through: Model or {model, ...}, self-associations, paired associations over one through (Sequelize deletes and rewrites keys, belongs-to-many.js:70-130): the facts it may add to the through table unknown (its column set not complete) SQ-V2
SQ-P1 failures loading the models or sync would hit, provable from the source (the refusal column lists each; lib/model.js:191-193, :247-258, :602-604, :715-717, :741-761, lib/sequelize.js:592-594, associations/belongs-to.js:51-53, has-one.js:53-55; the database's rejections by probe or oracle) diagnostic schema_model_import_failure (row named); no claim for the models involved refused (Revision 3: each failure the code refuses): (1) two models of the group with one table name; (2) two indexes of a table, or of two tables in one schema, with one explicit name; (3) an id attribute without primaryKey when no attribute is a primary key (load); (4) an attribute without a type (load); (5) an ENUM without values (load); (6) a createdAt, updatedAt or deletedAt option that is an empty string, null or a number (load); (7) more than one autoIncrement attribute (load); (8) an index without fields (load); (9) a belongsTo targetKey or hasOne sourceKey that is not an attribute of the other model (load); (10) an ENUM label that is not a string literal on postgres; (11) a default outside the ENUM's labels on postgres, mysql and mariadb; (12) a fn(...) default on sqlite; (13) a VIRTUAL attribute with unique; (14) two attributes with one column name; (15) autoIncrement on a type other than INTEGER, BIGINT or SMALLINT on postgres; (16) autoIncrement with a default on postgres; (17) autoIncrement on a sqlite primary key that is not the single INTEGER PRIMARY KEY; (18) an association or join table from a model with a schema to a target without one on postgres; (19) references naming a column the referenced table does not have; (20) an index naming a column the table does not have; (21) a references key, belongsTo targetKey or hasOne/hasMany sourceKey that is provably neither the primary key nor a unique column of the other table (not sqlite); (22) references to a table of the group that sync provably does not create (not sqlite); a failure marked (load) throws while the models load: the definitions and association calls after it in its module, and those of modules not proven to load before it, never run or may not (not claimed); other failures: assumed absent (SQ-V3) SQ-V3
SQ-U1 sequelize-cli / umzug migrations folders of the package unread_tools entry (found, not read yet) always unread -
SQ-V assumptions SQ-V1..SQ-V6 attached to every record of the group stated, never claimed as facts - -
D anything else: sequelize-typescript (@Table, @Column, ... ; developer decision 2026-11-13, capture moves to T018g6), other Sequelize majors, project wrappers (Temporal(X, sequelize)), hooks that change attributes, instance hooks (Revision 3: addHook or a hook-type method such as beforeDefine on the instance or on Sequelize's class, or a hooks key in the constructor options: every option- and attribute-derived fact of the group unknown, the group not claimed), addScope, queryInterface calls, models built in loops or functions (a class + init inside a CommonJS factory, the sequelize-cli model template: a marker), a model of another package on the instance (a marker on the instance's group), sequelize.import, init/define with computed attributes, directory loaders nothing; the table or column is partial with D as reason, or a marker diagnostic schema_model_unread (tool sequelize) for whole definitions always -

Rows SQ-U1 and SQ-V exist so the inventory can count every scope form and the contract test can name the assumption row. The claim-side rows are SQ-K1, K2, M1, M2, A1, A2, A3, O1, O2, R1, R2 (eleven).

Report a problem with this pageSource: docs/contract/claims/sequelize-models.md