discourse/db/migrate/20200320193612_back_fill_topic_timer_durations.rb
2020-03-23 09:38:18 +05:30

21 lines
494 B
Ruby

# 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