Repository navigation
feat: migrate model definitions to TypeScript - #15431
Conversation
|
Something else I'm considering: remove the |
WikiRik
left a comment
There was a problem hiding this comment.
Big PR indeed. I still have to look at the big changes to the model code but it sounds like a good approach for the future. Just a few comments from the files I've already viewed, it's great work as always
That might not be a bad idea, but can we do that in a separate PR? |
Yep |
WikiRik
left a comment
There was a problem hiding this comment.
Few minor remarks, but looking good!
|
I'll document the list of breaking changes & merge |
Pull Request Checklist
Description Of Change
Sorry for yet another big PR 😓
This PR migrates the entire model definition to TypeScript. It also lays the first stone to be able to add support for Data Mapper.
TypeScript and static properties don't play nice, so this PR takes a different, backwards compatible, approach:
ModelDefinition.ModelDefinitioninstance, accessible throughMyModel.modelDefinition.ModelDefinitioninstance per Sequelize instance. This is because, unlike Active Record Model, Data Mapper Models can be used with multiple Sequelize instances.ModelRepository. It does not currently do anything but it will serve the same purposes asModelDefinitionbut for methods that interact with a database. That's the file we'll progressively move model methods to as we migrate to TypeScript.Model.rawAttributeshas been removed because it served an ambiguous dual purpose. It has been split in two properties:ModelDefinition.rawAttributes: Attributes as they were configured by the user. This object is mutable, but should only be used if the user needs to modify the definition.ModelDefinition.attributes: Attributes that have been normalized by Sequelize. This object is immutable but should be used the user needs to read the stable definition.Misc Changes
ModelAttributeColumnOptionshas been renamed toAttributeOptionsto be less verboseModel.tableNameandModel.getTableNameare both deprecated in favor ofModel.tableModel.tableNamewas just the table without schemaModel.getTableNameadded a noise toString method we needed to deleteModel.tableworks likeModel.getTableNamebut is clean and its output is immutable.@Tabledecorators are mergedbeforeDefinitionRefreshandafterDefinitionRefreshwhich are triggered whenrefreshAttributesis calledsetterMethods,getterMethods(they were deprecated in v6). They throw an error if used to guide the user.fieldandfieldNamein attribute definitions are deprecated in favor ofcolumnNameandattributeNamerespectively (Clarify Column VS Attribute Terminology #14301)IndexTypecan be either fully lowercase or fully uppercase, since we accepted both anyway!references.model(the attribute option) now always references a model.references.tablehas been added to reference tables instead.references.tableModel.primaryKeyAttribute,Model.primaryKeyField: They're not compatible with composite primary keys.Model.primaryKeyAttributes,Model.fieldRawAttributesMap,Model.tableAttributes,Model.fieldAttributeMap,Model.refreshAttributes: UseModel.modelDefinitioninsteadModel#validators, useModel.modelDefinition.attributesinsteadBreaking changes
Don't forget the blank line in the commit message body