[deploy] Cleanup orphan data from buffer_updates (#10365)

* Cleanup orphan data from backup_data and buffer_updates

* Remove script as the table has been removed
This commit is contained in:
rhymes 2020-09-29 17:19:48 +02:00 committed by GitHub
parent 0ca4e8b371
commit 53deac75cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -0,0 +1,15 @@
module DataUpdateScripts
class NullifyOrphanRowsFromBufferUpdatesByComposerUserId
def run
# Nullify all BufferUpdates composer_user_id belonging to Users that don't exist anymore
ActiveRecord::Base.connection.execute(
<<~SQL.squish,
UPDATE buffer_updates
SET composer_user_id = NULL
WHERE composer_user_id IS NOT NULL
AND composer_user_id NOT IN (SELECT id FROM users);
SQL
)
end
end
end