Add Follow.unfollowed_at

The active scopes is used indirectly in the dossier<->gestionnaire associations: the existing tests in dossier and gestionnaire just work™.
This commit is contained in:
Nicolas Bouilleaud 2019-06-07 14:59:49 +02:00 committed by Pierre de La Morinerie
parent d417907f36
commit be4c575622
5 changed files with 29 additions and 6 deletions

View file

@ -0,0 +1,17 @@
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