title: How to create a UNIQUE constraint on a JSONB field with Sequelize
body: <p>I'm using the Sequelize ORM in NodeJS to manage a postgreSQL database.
  I'm using the JSONB datatype in my table, I need an index on the JSONB field and an unique constraint on a property of this JSON.
  If I have to do in a classic SQL here my script :</p>
  
  <pre><code>CREATE TABLE tableJson (id SERIAL PRIMARY KEY,
                          content JSONB NOT NULL);
  CREATE INDEX j_idx ON tableJson USING gin(content jsonb_path_ops);
  CREATE UNIQUE INDEX content_name_idx ON tableJson(((content-&gt;&gt;'name')::varchar));
  </code></pre>
  
  <p>I've found how to create the table with the INDEX but not how to deal with the UNIQUE constraint. Here is a sample of my script :</p>
  
  <pre><code>var tableJson = sequelize.define('tableJson', {
      content: Sequelize.JSONB
  }, {
      indexes: [{
          fields: ['content'],
          using: 'gin',
          operator: 'jsonb_path_ops'
      }
  });
  </code></pre>
  
  <p>Is there a solution for my problem? If not I'll probably use the sequelize.query method to execute raw query but this is not very evolutive.</p>
  
  <p>Any help would be appreciated!</p>