demarches-normaliennes/db/migrate/20190607124156_add_follow_unfollowed_at.rb

18 lines
722 B
Ruby
Raw Normal View History

class AddFollowUnfollowedAt < ActiveRecord::Migration[5.2]
# We need up/down migrations because `remove_index` doesnt allow `unique: true` and cant be properly rolled back.
def up
add_column :follows, :unfollowed_at, :datetime
remove_index :follows, [:gestionnaire_id, :dossier_id]
add_index :follows, [:gestionnaire_id, :dossier_id, :unfollowed_at], unique: true,
name: :uniqueness_index # We need a custom name because the autogenerated name would be too long
end
def down
remove_column :follows, :unfollowed_at
# We dont need to remove the index: dropping the column automatically deletes it.
add_index :follows, [:gestionnaire_id, :dossier_id], unique: true
end
end