0

I need to bootstrap my database table, this is the model definition (generated with sequelize-auto):

export class Player extends Model<PlayerAttributes, PlayerCreationAttributes> implements PlayerAttributes {
  player_id!: string
  jersey_number!: number
  roles!: Role[]
  first_name!: string
  last_name!: string
  country_id!: string
  team_id!: string
  traits!: Trait[]

  /** ASSOCIATIONS **/ 

  static initModel (sequelize: Sequelize.Sequelize): typeof Player {
    return Player.init({
      player_id: {
        type: DataTypes.UUID,
        allowNull: false,
        primaryKey: true
      },
      jersey_number: {
        type: DataTypes.INTEGER,
        allowNull: false
      },
      roles: {
        type: DataTypes.ARRAY(DataTypes.ENUM('SETTER', 'LIBERO', 'OUTSIDE_HITTER', 'OPPOSITE_HITTER', 'MIDDLE_BLOCKER', 'DEFENSIVE_SPECIALIST')),
        allowNull: false
      },
      first_name: {
        type: DataTypes.STRING,
        allowNull: false
      },
      last_name: {
        type: DataTypes.STRING,
        allowNull: false
      },
      country_id: {
        type: DataTypes.UUID,
        allowNull: false,
        references: {
          model: 'Country',
          key: 'country_id'
        }
      },
      team_id: {
        type: DataTypes.UUID,
        allowNull: false,
        references: {
          model: 'Team',
          key: 'team_id'
        }
      },
      traits: {
        type: DataTypes.ARRAY(DataTypes.ENUM('MARKSMAN', 'MOVING_WALL', 'MASTER_MIND', 'METEOR_SERVE', 'VIGOROUS', 'GUARDIAN')),
        allowNull: false,
      }
    }, {
      sequelize,
      tableName: 'Player',
      schema: 'public',
      timestamps: false,
      indexes: [
        {
          name: 'Player_pk',
          unique: true,
          fields: [
            { name: 'player_id' },
          ]
        },
      ]
    })
  }
}

when running individual creates I get this successful output:

Executing (default): INSERT INTO "public"."Player" ("player_id","jersey_number","roles","first_name","last_name","country_id","team_id","traits") VALUES ($1,$2,$3,$4,$5,$6,$7,$8) RETURNING "player_id","jersey_number","roles","first_name","last_name","country_id","team_id","traits";

But when I try to run the more efficient bulkCreate I get this error:

 sql: `INSERT INTO "public"."Player" ("player_id","jersey_number","roles","first_name","last_name","country_id","team_id","traits") VALUES ('19bc996a-b386-446d-bbd1-5fc34820993a',96,ARRAY['SETTER','OPPOSITE_HITTER','OUTSIDE_HITTER']::"public"
."enum_Player_roles"[],'Gabriel','Ward','44a3ac8c-e324-4206-b564-efc93aa81bc9','884b32c1-a5ab-45ea-b5ba-806e3f20381a',ARRAY['METEOR_SERVE']::"public"."enum_Player_traits"[]) RETURNING "player_id","jersey_number","roles","first_name","last_name","country_id","team_id","traits";`,
    parameters: undefined
  },
  original: error: type "public.enum_Player_roles[]" does not exist

Because for some reason sequelize is casting my type with the wrong name:

  • "public.enum_Player_roles[]" should be just "public.role[]"
  • "public.enum_Player_traits[]" should be just "public.trait[]"

. How can I make it use the correct names?

Thanks in advance

  • Does this answer your question? [Sequelize Seeding ARRAY(ENUM)](https://stackoverflow.com/questions/58326145/sequelize-seeding-arrayenum) – Emma Aug 02 '23 at 15:00
  • Unfortunately is not the same issue. I could try to write the query manually, but that would defeat the purpose of a simple insert – Francisco Farías Aug 02 '23 at 15:27

0 Answers0