demarches-normaliennes/db/migrate/20190607124156_add_follow_unfollowed_at.rb
Nicolas Bouilleaud be4c575622 Add Follow.unfollowed_at
The active scopes is used indirectly in the dossier<->gestionnaire associations: the existing tests in dossier and gestionnaire just work™.
2019-06-12 17:33:53 +02:00

17 lines
722 B
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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