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

@Index not working

Open rafaeltortella opened this issue 4 years ago • 0 comments

Hello guys i have a model with an @Index, and after the first SequelizeTypescriptMigration.makeMigration, when i try to change anything from that model i get the error:

TypeError: Cannot set property 'actionType' of undefined
    at /home/projects/Projects/iron-service/node_modules/sequelize-typescript-migration/src/utils/getDiffActionsFromTables.ts:134:10
    at Array.forEach (<anonymous>)
    at Object.getDiffActionsFromTables [as default] (/home/projects/Projects/iron-service/node_modules/sequelize-typescript-migration/src/utils/getDiffActionsFromTables.ts:35:14)
    at Function.SequelizeTypescriptMigration.makeMigration (/home/projects/Projects/iron-service/node_modules/sequelize-typescript-migration/src/index.ts:74:51)
    at bootstrap (/home/projects/Projects/iron-service/config/migrateMake.ts:23:20)

Debugging the lib i found inside getDiffActionsFromTable when is the condition:

if (df.path[1] === "indexes") {
                        const tableName = df.path[0];
                        const copied = df.rhs // IS UNDEFINED
                            ? JSON.parse(JSON.stringify(df.rhs))
                            : undefined;
                        const index = copied;

                        index.actionType = "addIndex";
                        index.tableName = tableName;
                        index.depends = [tableName];
                        actions.push(index);
                        break;
                    }

The df.rhs is undefined so the code will break on line 82: index.actionType = "addIndex";

My Model:

import {
  Table, Column, Model, CreatedAt, AllowNull, DataType, Unique, Index, NotEmpty,
} from 'sequelize-typescript';

@Table
export default class ApiAudit extends Model<ApiAudit> {
  @NotEmpty
  @Column
  vaultAccountId: number;

  @NotEmpty
  @Column
  eventName: string;

  @NotEmpty
  @Unique
  @Index
  @Column
  txHash: string;

  @AllowNull(false)
  @Column(DataType.JSON)
  data: unknown;

  @CreatedAt
  createdAt: Date;
}

When i use the const HashIndex = createIndexDecorator(); to create an index, everything works.

Thanks.

rafaeltortella avatar Mar 24 '21 13:03 rafaeltortella