Merge pull request #1088 from ComputerDruid/fix-ipv6

Fix ipv6 addresses in the database
This commit is contained in:
Sam
2013-06-25 17:25:48 -07:00
10 changed files with 53 additions and 16 deletions
@@ -0,0 +1,21 @@
require 'ipaddr'
class ChangeIpToInetInTopicLinkClicks < ActiveRecord::Migration
def up
add_column :topic_link_clicks, :ip_address, :inet
execute "UPDATE topic_link_clicks SET ip_address = inet(
(ip >> 24 & 255) || '.' ||
(ip >> 16 & 255) || '.' ||
(ip >> 8 & 255) || '.' ||
(ip >> 0 & 255)
);"
change_column :topic_link_clicks, :ip_address, :inet, { :null => false }
remove_column :topic_link_clicks, :ip
end
def down
raise ActiveRecord::IrreversibleMigration
end
end
@@ -0,0 +1,22 @@
require 'ipaddr'
class ChangeIpToInetInViews < ActiveRecord::Migration
def up
table = :views
add_column table, :ip_address, :inet
execute "UPDATE views SET ip_address = inet(
(ip >> 24 & 255) || '.' ||
(ip >> 16 & 255) || '.' ||
(ip >> 8 & 255) || '.' ||
(ip >> 0 & 255)
);"
change_column table, :ip_address, :inet, { :null => false }
remove_column table, :ip
end
def down
raise ActiveRecord::IrreversibleMigration
end
end