From d44b5afd191bd29a509e5dfcd9a85c608824f802 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Mon, 20 May 2019 11:37:34 +0200 Subject: [PATCH] Fixed bug: - Migration gets executed unnecessarily on newly installed systems. - Migration looks for `changed_at` column which should be `updated_at` instead. - Migration removes `limit: 3` on `created_at` timestamp colums (MySQL millisecond support). --- db/migrate/20150979000001_update_timestamps.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/db/migrate/20150979000001_update_timestamps.rb b/db/migrate/20150979000001_update_timestamps.rb index 39f9b2df6..0fdefb07c 100644 --- a/db/migrate/20150979000001_update_timestamps.rb +++ b/db/migrate/20150979000001_update_timestamps.rb @@ -1,15 +1,18 @@ class UpdateTimestamps < ActiveRecord::Migration[4.2] def up + # return if it's a new setup + return if !Setting.find_by(name: 'system_init_done') + # get all models Models.all.each_value do |value| next if !value next if !value[:attributes] - if value[:attributes].include?('changed_at') - ActiveRecord::Migration.change_column value[:table].to_sym, :changed_at, :datetime, null: false + if value[:attributes].include?('updated_at') + ActiveRecord::Migration.change_column value[:table].to_sym, :updated_at, :datetime, limit: 3, null: false end if value[:attributes].include?('created_at') - ActiveRecord::Migration.change_column value[:table].to_sym, :created_at, :datetime, null: false + ActiveRecord::Migration.change_column value[:table].to_sym, :created_at, :datetime, limit: 3, null: false end end end