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.
This commit is contained in:
evazion
2017-01-12 07:17:11 +00:00
parent 3ca638bc92
commit 26c193dfb3
3 changed files with 16 additions and 2 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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');