Skip to content

Instantly share code, notes, and snippets.

@dpickett
Created September 27, 2012 16:18
Show Gist options
  • Save dpickett/3794909 to your computer and use it in GitHub Desktop.
Save dpickett/3794909 to your computer and use it in GitHub Desktop.
timestamp_fix.rb
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