title: Separate indexes on two columns and unique constraint on the pair in Rails
body: <p>My app uses a PostgreSQL database. I've got a migration that looks like this:</p>
  
  <pre><code>class CreateTagAssignments &lt; ActiveRecord::Migration
    def change
      create_table :tag_assignments do |t|
        t.integer :tag_id
        t.integer :quote_id
        t.integer :user_id
  
        t.timestamps
      end
  
      add_index :tag_assignments, :tag_id
      add_index :tag_assignments, :quote_id
    end
  end
  </code></pre>
  
  <p>Records will be quite frequently searched by these two columns so I want to have a separate index for each. But now I'd like to enforce uniqueness of the pair (<code>tag_id</code>, <code>quote_id</code>) on the database level. I tried <code>add_index :tag_assignments, [:tag_id, :quote_id], unique: true</code> but I got the error: </p>
  
  <pre><code>PG::Error: ERROR:  could not create unique index "index_tag_assignments_on_tag_id_and_quote_id"
  DETAIL:  Key (tag_id, quote_id)=(10, 1) is duplicated.
  : CREATE UNIQUE INDEX "index_tag_assignments_on_tag_id_and_quote_id" ON "tag_assignments" ("tag_id", "quote_id")
  </code></pre>
  
  <p>So multiple indexes apparently do the job of a multi-column index? If so, then I could add the constraint with <code>ALTER TABLE ... ADD CONSTRAINT</code>, but how can I do it in ActiveRecord?</p>
  
  <p>edit: manually performing <code>ALTER TABLE ... ADD CONSTRAINT</code> produces the same error.</p>