TransactionTimestamps
Transaction timestamps sets a Rails model's created_at and updated_at timestamps to the database transaction time,
rather than the current time. This is useful for aligning the timestamps of different models saved within a single
transaction to be exactly the same.
Installation
Add this line to your application's Gemfile:
gem 'transaction_timestamps'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install transaction_timestamps
Usage
In an initializer (eg. config/initializers/transaction_timestamps.rb), flag on transaction timestamps:
TransactionTimestamps.enabled = true
Any models created or updated within a transaction will then get the transaction timestamp.
Note: For postgresql databases, the timestamp is generated from a SQL query for the actual transaction time. For other databases (where querying the transaction time is not supported), the current system time as of the first timestamping event in the transaction is used.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/coupa/transaction_timestamps.
License
The gem is available as open source under the terms of the MIT License.