Skip to content

add user_last_logins to sql #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 28, 2025
Merged
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
26 changes: 26 additions & 0 deletions tools/docker-dev/sql/bootstrap.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ CREATE TABLE `audit_log` (
`recipient` varchar(128) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

CREATE TABLE user_last_logins (
`operator` varchar(128) NOT NULL,
`last_login` timestamp NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

CREATE TABLE `events` (
`id` int(11) NOT NULL,
`operator` varchar(128) NOT NULL,
Expand Down Expand Up @@ -138,6 +143,9 @@ ALTER TABLE `account_deletion_requests`
ALTER TABLE `audit_log`
ADD PRIMARY KEY (`id`);

ALTER TABLE `user_last_logins`
ADD PRIMARY KEY (`operator`);

ALTER TABLE `events`
ADD PRIMARY KEY (`id`);

Expand Down Expand Up @@ -211,6 +219,24 @@ ALTER TABLE `sso_log`
MODIFY `id` int(10) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;
COMMIT;

-- --------------------------------------------------------

--
-- automatically update `user_last_logins` from `audit_log`
--
DELIMITER //
CREATE TRIGGER update_last_login
AFTER INSERT ON audit_log
FOR EACH ROW
BEGIN
IF NEW.action_type = 'user_login' THEN
INSERT INTO user_last_logins (operator, last_login)
VALUES (NEW.operator, NEW.timestamp)
ON DUPLICATE KEY UPDATE last_login = NEW.timestamp;
END IF;
END;//
DELIMITER ;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Loading