blob: 7097247231681e45ad55a5a834bd60b69f8e20fb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# frozen_string_literal: true
class CleanupInvalidContacts < ActiveRecord::Migration[5.1]
class Contact < ApplicationRecord
belongs_to :user
belongs_to :person
has_many :aspect_memberships, dependent: :delete_all
before_destroy :destroy_notifications
def destroy_notifications
Notification.where(
target_type: "Person",
target_id: person_id,
recipient_id: user_id,
type: "Notifications::StartedSharing"
).destroy_all
end
end
class User < ApplicationRecord
end
class Person < ApplicationRecord
belongs_to :owner, class_name: "User", optional: true
end
class Notification < ApplicationRecord
self.inheritance_column = nil
has_many :notification_actors, dependent: :delete_all
end
class NotificationActor < ApplicationRecord
end
class AspectMembership < ApplicationRecord
end
def up
Contact.left_outer_joins(:user).where("users.id is NULL").destroy_all
Contact.left_outer_joins(person: :owner).where("people.owner_id is NOT NULL").where("users.id is NULL").destroy_all
end
end
|