sequelize-typescript-generator
sequelize-typescript-generator copied to clipboard
fixing allowNull, onDelete, onChange, deferrable
fixes and new things for postgresql
- fixing allowNull
- adding onDelete and onChange for foreign keys
- adding deferrable information to be used later in ts model for foreign keys.
For point 3 I had to comment out the last piece for deferrable in ModelBuilder.ts, can you please give me a hint how this should be handled - I suspect I need to build some ts property - although I'm not sure how
@obecny Hi, thanks a lot for the contribution! I am on vacation now, will look into that when I am back 🙂
@spinlud hey any update on that, thx
Hi @obecny, sry for the long delay. I am afraid I am not very familiar with deferred constraints in Postgre, thus I am not sure how much can I help here.
I can be wrong but probably you need to import these types from Sequelize?
import { ModelAttributeColumnOptions, ModelAttributeColumnReferencesOptions } from 'sequelize';
// [...]
const props: Partial<ModelAttributeColumnOptions> = {
...col.originName && col.name !== col.originName && { field: col.originName },
...col.primaryKey && { primaryKey: col.primaryKey },
...col.autoIncrement && { autoIncrement: col.autoIncrement },
...col.allowNull && { allowNull: col.allowNull },
...col.dataType && { type: col.dataType },
...col.comment && { comment: col.comment },
...col.defaultValue && { defaultValue: col.defaultValue },
...col.onUpdate && { onUpdate: col.onUpdate },
...col.onDelete && { onDelete: col.onDelete },
// @TODO fix this by creating a typescript definition for model
...col.references && { references: col.references as ModelAttributeColumnReferencesOptions },
};
// [...]
Some questions:
Can we extended the onUpdate and onDelete behaviours to all the dialects (probably needed a query update)?
Do you think will be possible to add tests for deferrable constraints in Postgre?