correct migration so it always populates column

This commit is contained in:
Sam Saffron 2017-05-25 18:50:51 -04:00
parent 7d59ff67b8
commit 6674611960

View File

@ -4,11 +4,11 @@ class AddUnreadTrackingColumns < ActiveRecord::Migration
add_column :topics, :last_unread_at, :datetime, null: false, default: "epoch" add_column :topics, :last_unread_at, :datetime, null: false, default: "epoch"
execute <<SQL execute <<SQL
UPDATE topics SET last_unread_at = ( UPDATE topics SET last_unread_at = COALESCE((
SELECT MAX(created_at) SELECT MAX(created_at)
FROM posts FROM posts
WHERE topics.id = posts.topic_id WHERE topics.id = posts.topic_id
) ), current_timestamp)
SQL SQL
execute <<SQL execute <<SQL