From 26c193dfb3c9d3fe443b8fef9dc4c545476e23b0 Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 12 Jan 2017 07:17:11 +0000 Subject: [PATCH] Change post_appeals.creator_ip_addr from integer to inet. The existing values are garbage, rails stored e.g. "87.126.98.245" as "87.126.98.245".to_i => 87. The column is nulled to indicate these IPs are unknown. --- app/logical/moderator/ip_addr_search.rb | 2 +- ...12060921_change_ip_addr_to_inet_on_post_appeals.rb | 11 +++++++++++ db/structure.sql | 5 ++++- 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20170112060921_change_ip_addr_to_inet_on_post_appeals.rb diff --git a/app/logical/moderator/ip_addr_search.rb b/app/logical/moderator/ip_addr_search.rb index 7b6994b28..b918e39b0 100644 --- a/app/logical/moderator/ip_addr_search.rb +++ b/app/logical/moderator/ip_addr_search.rb @@ -55,7 +55,7 @@ module Moderator add_row(sums, WikiPageVersion.where(updater: users).group(:updater_ip_addr).count) add_row(sums, Comment.where(creator: users).group(:ip_addr).count) add_row(sums, Dmail.where(from: users).group(:creator_ip_addr).count) - add_row(sums, PostAppeal.where(creator: users).group(:creator_ip_addr).count) + add_row(sums, PostAppeal.where(creator: users).where.not(creator_ip_addr: nil).group(:creator_ip_addr).count) add_row(sums, PostFlag.where(creator: users).group(:creator_ip_addr).count) add_row(sums, Upload.where(uploader: users).group(:uploader_ip_addr).count) add_row(sums, User.where(id: users).group(:last_ip_addr).count) diff --git a/db/migrate/20170112060921_change_ip_addr_to_inet_on_post_appeals.rb b/db/migrate/20170112060921_change_ip_addr_to_inet_on_post_appeals.rb new file mode 100644 index 000000000..21d81ec7f --- /dev/null +++ b/db/migrate/20170112060921_change_ip_addr_to_inet_on_post_appeals.rb @@ -0,0 +1,11 @@ +class ChangeIpAddrToInetOnPostAppeals < ActiveRecord::Migration + def up + execute "set statement_timeout = 0" + change_column_null :post_appeals, :creator_ip_addr, true + execute "ALTER TABLE post_appeals ALTER COLUMN creator_ip_addr TYPE inet USING NULL" + end + + def down + raise ActiveRecord::IrreversibleMigration, "Can't recover the lost data" + end +end diff --git a/db/structure.sql b/db/structure.sql index f78d52df7..295fd7ca4 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -2557,7 +2557,7 @@ CREATE TABLE post_appeals ( id integer NOT NULL, post_id integer NOT NULL, creator_id integer NOT NULL, - creator_ip_addr integer NOT NULL, + creator_ip_addr inet, reason text, created_at timestamp without time zone, updated_at timestamp without time zone @@ -7438,3 +7438,6 @@ INSERT INTO schema_migrations (version) VALUES ('20161229001201'); INSERT INTO schema_migrations (version) VALUES ('20170106012138'); INSERT INTO schema_migrations (version) VALUES ('20170112021922'); + +INSERT INTO schema_migrations (version) VALUES ('20170112060921'); +