Created
May 3, 2018 04:24
-
-
Save Uysim/27b068140642a66b2575a7777ec0912a to your computer and use it in GitHub Desktop.
Rails Migration
This file contains hidden or 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 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