Only run the data migration if there are profiles in the db
This commit is contained in:
parent
c7b4e2b4f4
commit
e22701a12d
1 changed files with 23 additions and 19 deletions
|
|
@ -1,5 +1,7 @@
|
|||
class UniqueIndexOnProfile < ActiveRecord::Migration
|
||||
class Profile < ActiveRecord::Base; end
|
||||
def self.up
|
||||
if Profile.count > 0
|
||||
conn = ActiveRecord::Base.connection
|
||||
columns = conn.columns("profiles").map{|c| c.name}
|
||||
["id", "created_at", "updated_at"].each{|n| columns.delete(n)}
|
||||
|
|
@ -22,6 +24,7 @@ class UniqueIndexOnProfile < ActiveRecord::Migration
|
|||
end
|
||||
conn.execute("DELETE FROM profiles
|
||||
WHERE profiles.id IN (#{undesired_profile_ids.join(",")});") unless undesired_profile_ids.empty?
|
||||
end
|
||||
|
||||
remove_index :profiles, :person_id
|
||||
add_index :profiles, :person_id, :unique => true
|
||||
|
|
@ -29,5 +32,6 @@ class UniqueIndexOnProfile < ActiveRecord::Migration
|
|||
|
||||
def self.down
|
||||
remove_index :profiles, :person_id
|
||||
add_index :profiles, :person_id
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue