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
3 changed files with 22 additions and 2 deletions

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