Prepared for rails 5.

This commit is contained in:
Martin Edenhofer 2015-09-27 23:01:45 +02:00
parent 53ff4fc0db
commit 0ecf07ff74
2 changed files with 20 additions and 2 deletions

View file

@ -0,0 +1,15 @@
class UpdateTimestamps < ActiveRecord::Migration
def up
# get all models
Models.all.each {|model, 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
end
if value[:attributes].include?('created_at')
ActiveRecord::Migration.change_column value[:table].to_sym, :created_at, :datetime, null: false
end
}
end
end

View file

@ -11,12 +11,14 @@ returns
{
Some::Classname1 => {
attributes: ['id', 'name', '...']
reflections: ...model.reflections...
attributes: ['id', 'name', '...'],
reflections: ...model.reflections...,
table: 'some_classname1s',
},
Some::Classname2 => {
attributes: ['id', 'name', '...']
reflections: ...model.reflections...
table: 'some_classname2s',
},
}
@ -43,6 +45,7 @@ returns
all[model_class] = {}
all[model_class][:attributes] = model_class.attribute_names
all[model_class][:reflections] = model_class.reflections
all[model_class][:table] = model_class.table_name
#puts model_class
#puts "rrrr #{all[model_class][:attributes]}"
#puts " #{model_class.attribute_names.inspect}"