Remove IP tracking columns from users table (#16409)
parent
b52fdb4c6f
commit
8e84ebf0cb
19 changed files with 141 additions and 75 deletions
@ -0,0 +1,19 @@ |
||||
# frozen_string_literal: true |
||||
# == Schema Information |
||||
# |
||||
# Table name: user_ips |
||||
# |
||||
# user_id :bigint(8) primary key |
||||
# ip :inet |
||||
# used_at :datetime |
||||
# |
||||
|
||||
class UserIp < ApplicationRecord |
||||
self.primary_key = :user_id |
||||
|
||||
belongs_to :user, foreign_key: :user_id |
||||
|
||||
def readonly? |
||||
true |
||||
end |
||||
end |
@ -0,0 +1,5 @@ |
||||
# frozen_string_literal: true |
||||
|
||||
class REST::Admin::IpSerializer < ActiveModel::Serializer |
||||
attributes :ip, :used_at |
||||
end |
@ -0,0 +1,5 @@ |
||||
class CreateUserIps < ActiveRecord::Migration[6.1] |
||||
def change |
||||
create_view :user_ips |
||||
end |
||||
end |
@ -0,0 +1,12 @@ |
||||
# frozen_string_literal: true |
||||
|
||||
class RemoveCurrentSignInIpFromUsers < ActiveRecord::Migration[5.2] |
||||
disable_ddl_transaction! |
||||
|
||||
def change |
||||
safety_assured do |
||||
remove_column :users, :current_sign_in_ip, :inet |
||||
remove_column :users, :last_sign_in_ip, :inet |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,26 @@ |
||||
SELECT |
||||
user_id, |
||||
ip, |
||||
max(used_at) AS used_at |
||||
FROM ( |
||||
SELECT |
||||
id AS user_id, |
||||
sign_up_ip AS ip, |
||||
created_at AS used_at |
||||
FROM users |
||||
WHERE sign_up_ip IS NOT NULL |
||||
UNION ALL |
||||
SELECT |
||||
user_id, |
||||
ip, |
||||
updated_at |
||||
FROM session_activations |
||||
UNION ALL |
||||
SELECT |
||||
user_id, |
||||
ip, |
||||
created_at |
||||
FROM login_activities |
||||
WHERE success = 't' |
||||
) AS t0 |
||||
GROUP BY user_id, ip |
Loading…
Reference in new issue