Open yunixon opened 2 months ago
Fixes for Rails 7.2 are not released yet. Please try this:
gem 'unread', github: 'ledermann/unread'
7.2 support now seems to be there but I'm getting issues caused by the precision on timestamp on ReadMark vs datetime on my rails models.
This only came to light in dev while immediately marking an issue read under :show in the controller. That creates a timestamp on the read_mark without milliseconds while the datetime column on the model supports milliseconds.
This results in the read_mark appearing to be created before the associated record.
[#<ReadMark:0x0000717b61e4f798
id: 9,
readable_type: "Issue",
readable_id: 6,
reader_type: "User",
reader_id: 1,
timestamp: "2024-10-09 10:00:53.000000000 +0000">]
3.3.1 :011 > i
=>
#<Issue:0x0000717b621acf80
id: 6,
subject: "test this please",
description: "let's see",
user_id: 1,
created_at: "2024-10-09 10:00:53.231852000 +0000",
updated_at: "2024-10-09 10:00:53.231852000 +0000">
My fix was to change the migration adding precision: 6
def self.up
create_table ReadMark, force: true, options: create_options do |t|
t.references :readable, polymorphic: { null: false }
t.references :reader, polymorphic: { null: false }
t.datetime :timestamp, null: false, precision: 6
end
add_index ReadMark, [:reader_id, :reader_type, :readable_type, :readable_id], name: 'read_marks_reader_readable_index', unique: true
end
If someone is looking for a migration for the solution from @chriswnl:
class AddPrecisionToReadMarks < ActiveRecord::Migration[8.0]
def change
change_column :read_marks, :timestamp, :datetime, precision: 6
end
end
Maybe unrelated to this, but with Rails 8 I also ran into issues when immediately marking a created entity as read. For now I manually increase the timestamp by 1 second 🫤
current_user.read_marks.where(readable: things).update_all("timestamp = timestamp + interval '1 seconds'")
I'm using postgres btw.
Get error with rails 7.2.1
return to rails 7.1.4 and works good
Diff: