diff options
author | Bogdan Gusiev <agresso@gmail.com> | 2015-09-22 12:48:50 +0300 |
---|---|---|
committer | Bogdan Gusiev <agresso@gmail.com> | 2015-09-23 13:29:08 +0300 |
commit | d03f5196657bf466d7576cd6cbd4886db030723b (patch) | |
tree | 29b1c6b120ebe89878905c0b112892d5300f6585 /activerecord/test/schema | |
parent | 8842ce239562d3fbc82198ac3c4618935134ff39 (diff) | |
download | rails-d03f5196657bf466d7576cd6cbd4886db030723b.tar.gz rails-d03f5196657bf466d7576cd6cbd4886db030723b.tar.bz2 rails-d03f5196657bf466d7576cd6cbd4886db030723b.zip |
Fixed taking precision into count when assigning a value to timestamp attribute
Timestamp column can have less precision than ruby timestamp
In result in how big a fraction of a second can be stored in the
database.
m = Model.create!
m.created_at.usec == m.reload.created_at.usec
# => false
# due to different seconds precision in Time.now and database column
If the precision is low enough, (mysql default is 0, so it is always low
enough by default) the value changes when model is reloaded from the
database. This patch fixes that issue ensuring that any timestamp
assigned as an attribute is converted to column precision under the
attribute.
Diffstat (limited to 'activerecord/test/schema')
-rw-r--r-- | activerecord/test/schema/schema.rb | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index d318f3a968..ae183ade81 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -251,10 +251,10 @@ ActiveRecord::Schema.define do create_table :developers, force: true do |t| t.string :name t.integer :salary, default: 70000 - t.datetime :created_at - t.datetime :updated_at - t.datetime :created_on - t.datetime :updated_on + t.datetime :created_at, precision: 6 + t.datetime :updated_at, precision: 6 + t.datetime :created_on, precision: 6 + t.datetime :updated_on, precision: 6 end create_table :developers_projects, force: true, id: false do |t| @@ -353,7 +353,7 @@ ActiveRecord::Schema.define do create_table :invoices, force: true do |t| t.integer :balance - t.datetime :updated_at + t.datetime :updated_at, precision: 6 end create_table :iris, force: true do |t| @@ -503,7 +503,7 @@ ActiveRecord::Schema.define do create_table :owners, primary_key: :owner_id, force: true do |t| t.string :name - t.column :updated_at, :datetime + t.column :updated_at, :datetime, precision: 6 t.column :happy_at, :datetime t.string :essay_id end @@ -521,10 +521,10 @@ ActiveRecord::Schema.define do t.column :color, :string t.column :parrot_sti_class, :string t.column :killer_id, :integer - t.column :created_at, :datetime - t.column :created_on, :datetime - t.column :updated_at, :datetime - t.column :updated_on, :datetime + t.column :created_at, :datetime, precision: 0 + t.column :created_on, :datetime, precision: 0 + t.column :updated_at, :datetime, precision: 0 + t.column :updated_on, :datetime, precision: 0 end create_table :parrots_pirates, id: false, force: true do |t| @@ -567,15 +567,15 @@ ActiveRecord::Schema.define do create_table :pets, primary_key: :pet_id, force: true do |t| t.string :name t.integer :owner_id, :integer - t.timestamps null: false + t.timestamps null: false, precision: 6 end create_table :pirates, force: true do |t| t.column :catchphrase, :string t.column :parrot_id, :integer t.integer :non_validated_parrot_id - t.column :created_on, :datetime - t.column :updated_on, :datetime + t.column :created_on, :datetime, precision: 6 + t.column :updated_on, :datetime, precision: 6 end create_table :posts, force: true do |t| @@ -685,7 +685,7 @@ ActiveRecord::Schema.define do create_table :ship_parts, force: true do |t| t.string :name t.integer :ship_id - t.datetime :updated_at + t.datetime :updated_at, precision: 6 end create_table :prisoners, force: true do |t| @@ -778,7 +778,7 @@ ActiveRecord::Schema.define do t.string :parent_title t.string :type t.string :group - t.timestamps null: true + t.timestamps null: true, precision: 6 end create_table :toys, primary_key: :toy_id, force: true do |t| |