Skip to content
Draft
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
8 changes: 8 additions & 0 deletions migration/2.12.0.sql
Original file line number Diff line number Diff line change
@@ -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");
5 changes: 4 additions & 1 deletion schema/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -368,18 +368,21 @@ 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
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)
);

Expand Down