mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
9f6b7889a8
This fixes all known issues when connecting to discourse over IPv6. This table has no primary key, so the migration is done with update_all, for each ip address in the views table. Since this table can potentially grow quite large, this process might take a long time. I don't know any way around this, though. This migration uses a SQL command to populate the new field from the old one, so as not to rely on the View model class, which should keep the migration from failing if that class is modified in the future.
22 lines
489 B
Ruby
22 lines
489 B
Ruby
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
|