FIX: Backfill topic timer duration (#9249)

This commit is contained in:
Roman Rizzi 2020-03-23 01:08:18 -03:00 committed by GitHub
parent 3189dab622
commit c4bc734b11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 2 deletions

View File

@ -89,7 +89,7 @@ TopicStatusUpdater = Struct.new(:topic, :user) do
def message_for_autoclosed(locale_key)
num_minutes =
if @topic_status_update&.based_on_last_post
@topic_status_update.duration.hours
(@topic_status_update.duration || 0).hours
elsif @topic_status_update&.created_at
Time.zone.now - @topic_status_update.created_at
else

View File

@ -0,0 +1,20 @@
# frozen_string_literal: true
class BackFillTopicTimerDurations < ActiveRecord::Migration[6.0]
def up
DB.exec <<~SQL
UPDATE topic_timers
SET duration = 0
WHERE duration IS NULL AND (execute_at IS NULL OR created_at IS NULL)
SQL
DB.exec <<~SQL
UPDATE topic_timers
SET duration = EXTRACT(EPOCH FROM execute_at - created_at) / 3600
WHERE duration IS NULL AND execute_at IS NOT NULL AND created_at IS NOT NULL
SQL
end
def down
end
end

View File

@ -470,7 +470,7 @@ class PostCreator
if topic_timer &&
topic_timer.based_on_last_post &&
topic_timer.duration > 0
topic_timer.duration.to_i > 0
@topic.set_or_create_timer(TopicTimer.types[:close],
nil,