Skip to content

bulkCreate updateOnDuplicate ignores unique keys #12742

Closed

Description

@oxyii

Issue Description

(ref #11569)

bulkCreate updateOnDuplicate bug if unique composite index declared in model options instead of field options.

What are you doing?

const dbInstance = require('./db');

const Model1 = dbInstance.define('Model1', {
  field1: DataTypes.STRING,
  field2: DataTypes.STRING,
}, {
  indexes: [
    {
      name: 'compositeUnique',
      fields: ['field1', 'field2'],
      unique: true,
    },
  ],
})

const Model2 = dbInstance.define('Model2', {
  field1: {
    type: DataTypes.STRING,
    unique: 'compositeUnique',
  },
  field2: {
    type: DataTypes.STRING,
    unique: 'compositeUnique',
  },
})

What do you expect to happen?

The same behavior in both cases

What is actually happening?

// get Model1.uniqueKeys
{}
// get Model2.uniqueKeys
{
  "compositeUnique": { /* fields, name.... */ },
}

because of this Insert request with ON CONFLICT fragment use primaryKey only in first case (Model1)

Additional context

nope

Environment

  • Sequelize version: 6.3.5
  • Node.js version: 12.18.4
  • Operating System: tested on Ubuntu 18.04, 20.04 and MacOS 10.15
  • If TypeScript related: TypeScript version: irrelevant, tried on TS 4.0.3 and pure js

Issue Template Checklist

How does this problem relate to dialects?

  • I think this problem happens regardless of the dialect.
  • I think this problem happens only for the following dialect(s):
  • I don't know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I don't know how to start, I would need guidance.
  • No, I don't have the time, although I believe I could do it if I had the time...
  • No, I don't have the time and I wouldn't even know how to start.

Activity

  1. kreinholt commented on May 7, 2021

    @kreinholt

    Some relevant pull requests that might solve this are: #12516 and #12547

  2. github-actions commented on Oct 29, 2021

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions