about summary refs log tree commit diff stats
path: root/db/migrate/20250512181245_add_latest_post_at_to_stream.rb
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2025-05-12 14:53:31 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2025-05-12 14:53:31 -0400
commitb7c5853de5f0f04625eab6389cba9de8b02e48fb (patch)
tree1764a974e1b93b024c90f98246590d0bac5430ef /db/migrate/20250512181245_add_latest_post_at_to_stream.rb
parent4016070f2caf30f576d0b0df8a65a7b4b468e951 (diff)
downloadthoughts-b7c5853de5f0f04625eab6389cba9de8b02e48fb.tar.gz
thoughts-b7c5853de5f0f04625eab6389cba9de8b02e48fb.tar.bz2
thoughts-b7c5853de5f0f04625eab6389cba9de8b02e48fb.zip
Added streams index
Diffstat (limited to 'db/migrate/20250512181245_add_latest_post_at_to_stream.rb')
-rw-r--r--db/migrate/20250512181245_add_latest_post_at_to_stream.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/db/migrate/20250512181245_add_latest_post_at_to_stream.rb b/db/migrate/20250512181245_add_latest_post_at_to_stream.rb new file mode 100644 index 0000000..9d753e3 --- /dev/null +++ b/db/migrate/20250512181245_add_latest_post_at_to_stream.rb
@@ -0,0 +1,21 @@
1class AddLatestPostAtToStream < ActiveRecord::Migration[7.1]
2 def up
3 add_column :streams, :latest_post_at, :datetime
4
5 Stream.all.each do |stream|
6 if stream.updates.empty?
7 stream.latest_post_at = stream.created_at
8 else
9 stream.latest_post_at = stream.updates.order(created_at: :desc).first.created_at
10 end
11
12 stream.save!
13 end
14
15 change_column_null :streams, :latest_post_at, false
16 end
17
18 def down
19 remove_column :streams, :latest_post_at, :datetime
20 end
21end