clear icon indicating copy to clipboard operation
clear copied to clipboard

Creating a UNIQUE constraint on multiple columns?

Open jubishop opened this issue 4 years ago • 2 comments

can Clear support unique constraints on multiple columns? for example:

CREATE TABLE table (
    c1 data_type,
    c2 data_type,
    c3 data_type,
    UNIQUE (c2, c3)
);

jubishop avatar Nov 23 '21 03:11 jubishop

@jubishop yes, you can create it with Clear migrations

For example:

class CreateUsers
  include Clear::Migration

  def change(direction)
    direction.up do
      create_table(:users) do |t|
        t.column :provider, :string, null: false
        t.column :provider_id, :integer, null: false
        t.column :name, :string
        t.column :created_at, :timestamp
        t.column :synced_at, :timestamp, null: false

        t.index [:provider, :provider_id], using: :btree, unique: true
      end
  end

    direction.down do
      execute("DROP TABLE users")
    end
  end
end

https://clear.gitbook.io/project/migrations/call-migration-script

mamantoha avatar Jan 05 '22 09:01 mamantoha