Skip to content

Instantly share code, notes, and snippets.

@Uysim
Created May 3, 2018 04:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Uysim/27b068140642a66b2575a7777ec0912a to your computer and use it in GitHub Desktop.
Save Uysim/27b068140642a66b2575a7777ec0912a to your computer and use it in GitHub Desktop.
Rails Migration
class MillisecondsDateTime < ActiveRecord::Migration
def up
ActiveRecord::Base.connection.tables.each do |table|
ActiveRecord::Base.connection.columns(table).each do |column|
if column.type == :datetime
change_column table, column.name, :datetime, limit: 6
add_index table, column.name
end
end
end
end
def down
ActiveRecord::Base.connection.tables.each do |table|
ActiveRecord::Base.connection.columns(table).each do |column|
if column.type == :datetime
change_column table, column.name, :datetime
remove_index table, column.name
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment