From 1440ac815435063330955a6c73ca5ba3b2304ba4 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 23 Dec 2014 11:05:50 +0200 Subject: [PATCH] Remove index only if exists Signed-off-by: Dmitriy Zaporozhets --- db/migrate/20141121161704_add_identity_table.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/db/migrate/20141121161704_add_identity_table.rb b/db/migrate/20141121161704_add_identity_table.rb index cf56fd6c227..a85b0426cec 100644 --- a/db/migrate/20141121161704_add_identity_table.rb +++ b/db/migrate/20141121161704_add_identity_table.rb @@ -14,7 +14,10 @@ SELECT provider, extern_uid, id FROM users WHERE provider IS NOT NULL eos - remove_index :users, ["extern_uid", "provider"] + if index_exists?(:users, ["extern_uid", "provider"]) + remove_index :users, ["extern_uid", "provider"] + end + remove_column :users, :extern_uid remove_column :users, :provider end @@ -35,6 +38,9 @@ eos end drop_table :identities - add_index "users", ["extern_uid", "provider"], name: "index_users_on_extern_uid_and_provider", unique: true, using: :btree + + unless index_exists?(:users, ["extern_uid", "provider"]) + add_index "users", ["extern_uid", "provider"], name: "index_users_on_extern_uid_and_provider", unique: true, using: :btree + end end end