2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2017-09-08 08:28:34 +00:00
|
|
|
class UpdateTimestamps < ActiveRecord::Migration[4.2]
|
2015-09-27 21:01:45 +00:00
|
|
|
def up
|
2019-05-20 09:37:34 +00:00
|
|
|
# return if it's a new setup
|
2020-08-03 08:35:43 +00:00
|
|
|
return if !Setting.exists?(name: 'system_init_done')
|
2019-05-20 09:37:34 +00:00
|
|
|
|
2015-09-27 21:01:45 +00:00
|
|
|
# get all models
|
2017-11-23 08:09:44 +00:00
|
|
|
Models.all.each_value do |value|
|
2015-09-27 21:01:45 +00:00
|
|
|
next if !value
|
|
|
|
next if !value[:attributes]
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2019-05-20 09:37:34 +00:00
|
|
|
if value[:attributes].include?('updated_at')
|
|
|
|
ActiveRecord::Migration.change_column value[:table].to_sym, :updated_at, :datetime, limit: 3, null: false
|
2015-09-27 21:01:45 +00:00
|
|
|
end
|
|
|
|
if value[:attributes].include?('created_at')
|
2019-05-20 09:37:34 +00:00
|
|
|
ActiveRecord::Migration.change_column value[:table].to_sym, :created_at, :datetime, limit: 3, null: false
|
2015-09-27 21:01:45 +00:00
|
|
|
end
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2015-09-27 21:01:45 +00:00
|
|
|
end
|
|
|
|
end
|