Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions configuration/pih/liquibase/sql/create_stored_procedures.sql
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,24 @@ END WHILE;

END
#
/*
Create temporary table temp_aggregate_login_data for use in retrieving latest login datetime and counts of each login
*/
#
DROP PROCEDURE IF EXISTS create_temp_aggregate_login_data;
#
CREATE PROCEDURE create_temp_aggregate_login_data()

BEGIN

drop temporary table if exists temp_aggregate_login_data;

create temporary table temp_aggregate_login_data
select user_id, count(*) "counts", max(event_datetime) "max_datetime"
FROM authentication_event_log
group by user_id;

create index temp_aggregate_login_data_ui on temp_aggregate_login_data(user_id);

END
#
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,14 @@ SET
ur.created_by = username(u.creator)
;

UPDATE temp_user_roles ur SET ur.last_login_date = user_latest_login(ur.user_id);
UPDATE temp_user_roles ur SET ur.num_logins_recorded = user_num_logins(ur.user_id);
call create_temp_aggregate_login_data();

UPDATE temp_user_roles ur
inner join temp_aggregate_login_data al on al.user_id = ur.user_id
SET ur.last_login_date = al.max_datetime,
ur.num_logins_recorded = al.counts;

ALTER TABLE temp_user_roles DROP COLUMN user_id;

-- Select all out of table
SELECT * FROM temp_user_roles;
SELECT * FROM temp_user_roles;
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,19 @@ SELECT u.user_id,
FROM users u
;

UPDATE temp_users u SET u.last_login_date = user_latest_login(u.user_id);
UPDATE temp_users u SET u.num_logins_recorded = user_num_logins(u.user_id);
UPDATE temp_users u SET u.mfa_status = user_property_value(u.user_id, 'authentication.secondaryType', 'disabled');
UPDATE temp_users u SET u.mfa_status = 'question' where u.mfa_status = 'secret';
UPDATE temp_users u SET u.mfa_status = 'authenticator' where u.mfa_status = 'totp';

call create_temp_aggregate_login_data();

UPDATE temp_users u
inner join temp_aggregate_login_data al on al.user_id = u.user_id
SET u.last_login_date = al.max_datetime,
u.num_logins_recorded = al.counts;


ALTER TABLE temp_users DROP COLUMN user_id;

-- Select all out of table
SELECT * FROM temp_users;
SELECT * FROM temp_users;