diff --git a/db/migrate/20150979000001_update_timestamps.rb b/db/migrate/20150979000001_update_timestamps.rb new file mode 100644 index 000000000..e99111781 --- /dev/null +++ b/db/migrate/20150979000001_update_timestamps.rb @@ -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 diff --git a/lib/models.rb b/lib/models.rb index ea73526a1..01d78617c 100644 --- a/lib/models.rb +++ b/lib/models.rb @@ -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}"