mirror of
https://github.com/discourse/discourse.git
synced 2026-08-13 06:25:11 -05:00
Merge pull request #1088 from ComputerDruid/fix-ipv6
Fix ipv6 addresses in the database
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user