diff --git a/CHANGELOG.md b/CHANGELOG.md index f177347b..b31b4435 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/). ### Added -- None +- Change `versions` table layout for performance ### Fixed diff --git a/lib/generators/paper_trail/install/templates/create_versions.rb.erb b/lib/generators/paper_trail/install/templates/create_versions.rb.erb index 651eb02d..d563a2f9 100644 --- a/lib/generators/paper_trail/install/templates/create_versions.rb.erb +++ b/lib/generators/paper_trail/install/templates/create_versions.rb.erb @@ -10,11 +10,7 @@ class CreateVersions < ActiveRecord::Migration<%= migration_version %> def change create_table :versions<%= versions_table_options %><%= version_table_primary_key_type %> do |t| - t.string :item_type<%= item_type_options %> - t.<%= item_id_type_options %> :item_id, null: false - t.string :event, null: false t.string :whodunnit - t.text :object, limit: TEXT_BYTES # Known issue in MySQL: fractional second precision # ------------------------------------------------- @@ -32,6 +28,11 @@ class CreateVersions < ActiveRecord::Migration<%= migration_version %> # MySQL users should use the following line for `created_at` # t.datetime :created_at, limit: 6 t.datetime :created_at + + t.<%= item_id_type_options %> :item_id, null: false + t.string :item_type<%= item_type_options %> + t.string :event, null: false + t.text :object, limit: TEXT_BYTES end add_index :versions, %i[item_type item_id] end