From 53deac75cde12bca16f680369424dfd187705f85 Mon Sep 17 00:00:00 2001 From: rhymes Date: Tue, 29 Sep 2020 17:19:48 +0200 Subject: [PATCH] [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 --- ...ows_from_buffer_updates_by_composer_user_id.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 lib/data_update_scripts/20200917135847_nullify_orphan_rows_from_buffer_updates_by_composer_user_id.rb diff --git a/lib/data_update_scripts/20200917135847_nullify_orphan_rows_from_buffer_updates_by_composer_user_id.rb b/lib/data_update_scripts/20200917135847_nullify_orphan_rows_from_buffer_updates_by_composer_user_id.rb new file mode 100644 index 000000000..ac32a0097 --- /dev/null +++ b/lib/data_update_scripts/20200917135847_nullify_orphan_rows_from_buffer_updates_by_composer_user_id.rb @@ -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