[deploy] Cleanup orphaned Ahoy rows in the DB (#9710)
* Cleanup orphaned Ahoy rows in the DB * Trigger Travis correctly
This commit is contained in:
parent
d5e13f5ba7
commit
3a56e4b442
1 changed files with 32 additions and 0 deletions
|
|
@ -0,0 +1,32 @@
|
|||
module DataUpdateScripts
|
||||
class RemoveOrphanedAhoyRows
|
||||
def run
|
||||
# Delete all Ahoy::Events belonging to users that don't exist anymore
|
||||
ActiveRecord::Base.connection.execute(
|
||||
<<~SQL,
|
||||
DELETE FROM ahoy_events
|
||||
WHERE user_id IS NOT NULL
|
||||
AND user_id NOT IN (SELECT id FROM users);
|
||||
SQL
|
||||
)
|
||||
|
||||
# Delete all Ahoy::Messages belonging to users that don't exist anymore
|
||||
ActiveRecord::Base.connection.execute(
|
||||
<<~SQL,
|
||||
DELETE FROM ahoy_messages
|
||||
WHERE user_id IS NOT NULL
|
||||
AND user_id NOT IN (SELECT id FROM users);
|
||||
SQL
|
||||
)
|
||||
|
||||
# Delete all Ahoy::Visits belonging to users that don't exist anymore
|
||||
ActiveRecord::Base.connection.execute(
|
||||
<<~SQL,
|
||||
DELETE FROM ahoy_visits
|
||||
WHERE user_id IS NOT NULL
|
||||
AND user_id NOT IN (SELECT id FROM users);
|
||||
SQL
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue