sequelize-typescript-generator icon indicating copy to clipboard operation
sequelize-typescript-generator copied to clipboard

fixing allowNull, onDelete, onChange, deferrable

Open obecny opened this issue 5 years ago • 3 comments

fixes and new things for postgresql

  1. fixing allowNull
  2. adding onDelete and onChange for foreign keys
  3. 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 avatar Aug 12 '20 19:08 obecny

@obecny Hi, thanks a lot for the contribution! I am on vacation now, will look into that when I am back 🙂

spinlud avatar Aug 13 '20 20:08 spinlud

@spinlud hey any update on that, thx

obecny avatar Oct 14 '20 17:10 obecny

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?

spinlud avatar Oct 17 '20 10:10 spinlud