Skip to content

Commit 1d120ab

Browse files
committed
Docs: Add warnings about time precision in MySQL
[ci skip]
1 parent 52745df commit 1d120ab

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,12 @@ widget.reload.wotsit # nil
839839
1. Not compatible with [transactional tests][34], aka. transactional fixtures.
840840
This is a known issue [#542](https://github.com/airblade/paper_trail/issues/542)
841841
that we'd like to solve.
842+
1. Requires database timestamp columns with fractional second precision.
843+
- Sqlite and postgres timestamps have fractional second precision by default.
844+
[MySQL timestamps do not][35]. Furthermore, MySQL 5.5 and earlier do not
845+
support fractional second precision at all.
846+
- Also, support for fractional seconds in MySQL was not added to
847+
rails until ActiveRecord 4.2 (https://github.com/rails/rails/pull/14359).
842848
1. PaperTrail can't restore an association properly if the association record
843849
can be updated to replace its parent model (by replacing the foreign key)
844850
1. Currently PaperTrail only support single `version_associations` table. The
@@ -1461,3 +1467,4 @@ Released under the MIT licence.
14611467
[32]: http://api.rubyonrails.org/classes/ActiveRecord/AutosaveAssociation.html#method-i-mark_for_destruction
14621468
[33]: https://github.com/airblade/paper_trail/wiki/Setting-whodunnit-in-the-rails-console
14631469
[34]: https://github.com/rails/rails/blob/591a0bb87fff7583e01156696fbbf929d48d3e54/activerecord/lib/active_record/fixtures.rb#L142
1470+
[35]: https://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html

lib/generators/paper_trail/templates/create_versions.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ def change
1313
t.string :event, :null => false
1414
t.string :whodunnit
1515
t.text :object, :limit => TEXT_BYTES
16+
17+
# Known issue in MySQL: fractional second precision
18+
# -------------------------------------------------
19+
#
20+
# MySQL timestamp columns do not support fractional seconds unless
21+
# defined with "fractional seconds precision". MySQL users should manually
22+
# add fractional seconds precision to this migration, specifically, to
23+
# the `created_at` column.
24+
# (https://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html)
25+
#
26+
# MySQL users should also upgrade to rails 4.2, which is the first
27+
# version of ActiveRecord with support for fractional seconds in MySQL.
28+
# (https://github.com/rails/rails/pull/14359)
29+
#
1630
t.datetime :created_at
1731
end
1832
add_index :versions, [:item_type, :item_id]

0 commit comments

Comments
 (0)