TopicLinkClick: convert 'ip' (bigint) -> 'ip_address' (inet)

When accessed over IPv6, the ip address of the user is a 128-bit number,
too big for PostgreSQL's bigint data type. Since PostgresSQL has the
built-in inet type, which handles both IPv4 and IPv6 addresses, we
should use that instead. Where this is done elsewhere in the codebase,
the column is called ip_address, so we should follow that convention as
well.

This migration uses a SQL command to populate the new field from the old
one, so as not to rely on the TopicLinkClick model class, which should
keep the migration from failing if that class is modified in the future.
This commit is contained in:
Dan Johnson
2013-06-25 19:41:19 -04:00
parent c79ab3fc2e
commit 2e478d8537
4 changed files with 27 additions and 8 deletions
+2 -2
View File
@@ -26,7 +26,7 @@ describe TopicLinkClick do
context 'create' do
before do
TopicLinkClick.create(topic_link: @topic_link, ip: '192.168.1.1')
TopicLinkClick.create(topic_link: @topic_link, ip_address: '192.168.1.1')
end
it 'creates the forum topic link click' do
@@ -39,7 +39,7 @@ describe TopicLinkClick do
end
it 'serializes and deserializes the IP' do
TopicLinkClick.first.ip.to_s.should == '192.168.1.1'
TopicLinkClick.first.ip_address.to_s.should == '192.168.1.1'
end
end
+1 -1
View File
@@ -236,7 +236,7 @@ describe TopicLink do
it 'has the correct results' do
TopicLink.extract_from(post)
topic_link = post.topic.topic_links.first
TopicLinkClick.create(topic_link: topic_link, ip: '192.168.1.1')
TopicLinkClick.create(topic_link: topic_link, ip_address: '192.168.1.1')
counts_for[post.id].should be_present
counts_for[post.id].find {|l| l[:url] == 'http://google.com'}[:clicks].should == 0