Created
September 27, 2012 16:18
-
-
Save dpickett/3794909 to your computer and use it in GitHub Desktop.
timestamp_fix.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FixTimestamps < ActiveRecord::Migration | |
def up | |
Dir.glob(Rails.root.join("app/models/**/*.rb")) do |f| | |
require f | |
end | |
ActiveRecord::Base.send(:subclasses).each do |klass| | |
[ | |
"created_at", | |
"updated_at" | |
].each do |col_name| | |
if klass.column_names.include?(col_name) | |
column = klass.columns.find{|i| i.name == col_name} | |
if column.null | |
change_column klass.table_name, col_name, :datetime, null: false | |
end | |
end | |
end | |
end | |
end | |
def down | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment