Prepared for rails 5.
This commit is contained in:
parent
53ff4fc0db
commit
0ecf07ff74
2 changed files with 20 additions and 2 deletions
15
db/migrate/20150979000001_update_timestamps.rb
Normal file
15
db/migrate/20150979000001_update_timestamps.rb
Normal 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
|
|
@ -11,12 +11,14 @@ returns
|
||||||
|
|
||||||
{
|
{
|
||||||
Some::Classname1 => {
|
Some::Classname1 => {
|
||||||
attributes: ['id', 'name', '...']
|
attributes: ['id', 'name', '...'],
|
||||||
reflections: ...model.reflections...
|
reflections: ...model.reflections...,
|
||||||
|
table: 'some_classname1s',
|
||||||
},
|
},
|
||||||
Some::Classname2 => {
|
Some::Classname2 => {
|
||||||
attributes: ['id', 'name', '...']
|
attributes: ['id', 'name', '...']
|
||||||
reflections: ...model.reflections...
|
reflections: ...model.reflections...
|
||||||
|
table: 'some_classname2s',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +45,7 @@ returns
|
||||||
all[model_class] = {}
|
all[model_class] = {}
|
||||||
all[model_class][:attributes] = model_class.attribute_names
|
all[model_class][:attributes] = model_class.attribute_names
|
||||||
all[model_class][:reflections] = model_class.reflections
|
all[model_class][:reflections] = model_class.reflections
|
||||||
|
all[model_class][:table] = model_class.table_name
|
||||||
#puts model_class
|
#puts model_class
|
||||||
#puts "rrrr #{all[model_class][:attributes]}"
|
#puts "rrrr #{all[model_class][:attributes]}"
|
||||||
#puts " #{model_class.attribute_names.inspect}"
|
#puts " #{model_class.attribute_names.inspect}"
|
||||||
|
|
Loading…
Reference in a new issue