Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a UNIQUE constraint on multiple columns? #223

Open
jubishop opened this issue Nov 23, 2021 · 1 comment
Open

Creating a UNIQUE constraint on multiple columns? #223

jubishop opened this issue Nov 23, 2021 · 1 comment

Comments

@jubishop
Copy link

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)
);
@mamantoha
Copy link
Contributor

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants