20150979000001_update_timestamps.rb 636 B

12345678910111213141516171819
  1. class UpdateTimestamps < ActiveRecord::Migration[4.2]
  2. def up
  3. # return if it's a new setup
  4. return if !Setting.exists?(name: 'system_init_done')
  5. # get all models
  6. Models.all.each_value do |value|
  7. next if !value
  8. next if !value[:attributes]
  9. if value[:attributes].include?('updated_at')
  10. ActiveRecord::Migration.change_column value[:table].to_sym, :updated_at, :datetime, limit: 3, null: false
  11. end
  12. if value[:attributes].include?('created_at')
  13. ActiveRecord::Migration.change_column value[:table].to_sym, :created_at, :datetime, limit: 3, null: false
  14. end
  15. end
  16. end
  17. end