From 3bba84ed3abbb9badfe8833e4aae7ceaeeb8586e Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Thu, 22 Aug 2024 15:45:59 +0300 Subject: [PATCH] Backfill block deactivates_at --- ...22121603_backfill_deactivates_at_in_user_blocks.rb | 11 +++++++++++ db/structure.sql | 1 + 2 files changed, 12 insertions(+) create mode 100644 db/migrate/20240822121603_backfill_deactivates_at_in_user_blocks.rb diff --git a/db/migrate/20240822121603_backfill_deactivates_at_in_user_blocks.rb b/db/migrate/20240822121603_backfill_deactivates_at_in_user_blocks.rb new file mode 100644 index 000000000..38c010c44 --- /dev/null +++ b/db/migrate/20240822121603_backfill_deactivates_at_in_user_blocks.rb @@ -0,0 +1,11 @@ +class BackfillDeactivatesAtInUserBlocks < ActiveRecord::Migration[7.1] + class UserBlock < ApplicationRecord; end + + disable_ddl_transaction! + + def up + UserBlock.where(:needs_view => false, :deactivates_at => nil).in_batches do |relation| + relation.update_all("deactivates_at = GREATEST(ends_at, updated_at)") + end + end +end diff --git a/db/structure.sql b/db/structure.sql index 18884b058..49cd4b9fb 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -3579,6 +3579,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('23'), ('22'), ('21'), +('20240822121603'), ('20240813070506'), ('20240618193051'), ('20240605134916'), -- 2.39.5