From 59d7b2dd56c54a22d70ca86eebdf50eee0e6756e Mon Sep 17 00:00:00 2001 From: Tom Egan Date: Fri, 20 Feb 2026 11:25:48 -0500 Subject: [PATCH] feature: add support for logging training sessions --- migration/2.12.0.sql | 8 ++++++++ schema/schema.sql | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 migration/2.12.0.sql diff --git a/migration/2.12.0.sql b/migration/2.12.0.sql new file mode 100644 index 0000000..984ece4 --- /dev/null +++ b/migration/2.12.0.sql @@ -0,0 +1,8 @@ +-- Add support for logging training + +INSERT INTO event_types(id, name) VALUES (6, "Training"); + +ALTER TABLE log ADD COLUMN trainee_card_id BIGINT(20) UNSIGNED DEFAULT NULL; +ALTER TABLE log ADD FOREIGN KEY log_trainee_card_id (trainee_card_id) REFERENCES cards (id); + +INSERT INTO schema_versioning(version, comment) VALUES ("2.12.0", "Migration Complete"); diff --git a/schema/schema.sql b/schema/schema.sql index d7a26c7..99a07d2 100644 --- a/schema/schema.sql +++ b/schema/schema.sql @@ -368,7 +368,8 @@ INSERT INTO event_types(id, name) VALUES (2, "Successful Authentication"), (3, "Deauthentication"), (4, "Startup Complete"), - (5, "Planned Shutdown"); + (5, "Planned Shutdown"), + (6, "Training"); -- List of events aka the access log @@ -376,10 +377,12 @@ CREATE TABLE log ( id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, event_type_id INT UNSIGNED NOT NULL, card_id BIGINT(20) UNSIGNED, + trainee_card_id BIGINT(20) UNSIGNED DEFAULT NULL, equipment_id INT UNSIGNED NOT NULL, time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), -- no foreign key for card_id because it may be an invalid card (failed auth) + FOREIGN KEY log_trainee_card_id (trainee_card_id) REFERENCES cards (id), FOREIGN KEY log_equipment_id (equipment_id) REFERENCES equipment (id) );