From a4a2ea47ba7f836283e93a8bc9aa619213e8e8dd Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Fri, 4 Apr 2025 10:11:32 +0200 Subject: [PATCH] Add script to populate last active at --- .../20250404072651_add_last_active_at_to_bubbles.rb | 1 - script/fill_last_active_at.rb | 9 +++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100755 script/fill_last_active_at.rb diff --git a/db/migrate/20250404072651_add_last_active_at_to_bubbles.rb b/db/migrate/20250404072651_add_last_active_at_to_bubbles.rb index 56db5d162..c1e9e4723 100644 --- a/db/migrate/20250404072651_add_last_active_at_to_bubbles.rb +++ b/db/migrate/20250404072651_add_last_active_at_to_bubbles.rb @@ -4,4 +4,3 @@ class AddLastActiveAtToBubbles < ActiveRecord::Migration[8.1] add_index :bubbles, %i[ last_active_at status ] end end - diff --git a/script/fill_last_active_at.rb b/script/fill_last_active_at.rb new file mode 100755 index 000000000..cfad6315a --- /dev/null +++ b/script/fill_last_active_at.rb @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby + +require_relative "../config/environment" + +ApplicationRecord.with_each_tenant do |tenant| + Bubble.find_each do |bubble| + bubble.update! last_active_at: bubble.events.last&.created_at || Time.current + end +end