bliss/migrations/001_add_logs.sql

19 lines
532 B
MySQL
Raw Normal View History

2024-10-29 21:29:40 -04:00
CREATE TABLE logs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
error BOOLEAN NOT NULL,
structure_id INTEGER NOT NULL,
route_id INTEGER,
content TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY(structure_id) REFERENCES structures(id),
FOREIGN KEY(route_id) REFERENCES routes(id)
);
-- Trigger to update `created_at` on insert
CREATE TRIGGER update_logs_created_at
AFTER INSERT ON logs
FOR EACH ROW
BEGIN
UPDATE logs SET created_at = CURRENT_TIMESTAMP WHERE id = NEW.id;
END;