2024-02-26 00:12:13 +01:00
|
|
|
CREATE TABLE IF NOT EXISTS time_reports (
|
|
|
|
id INTEGER PRIMARY KEY,
|
2024-02-27 08:05:07 +01:00
|
|
|
reportId TEXT DEFAULT (HEX(RANDOMBLOB(6))) NOT NULL UNIQUE,
|
2024-02-26 00:12:13 +01:00
|
|
|
project_id INTEGER NOT NULL,
|
|
|
|
start DATETIME NOT NULL,
|
|
|
|
end DATETIME NOT NULL,
|
2024-02-27 08:05:07 +01:00
|
|
|
FOREIGN KEY (project_id) REFERENCES projects (id) ON DELETE CASCADE
|
2024-02-26 00:12:13 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TRIGGER IF NOT EXISTS time_reports_start_before_end
|
|
|
|
BEFORE INSERT ON time_reports
|
|
|
|
FOR EACH ROW
|
|
|
|
BEGIN
|
|
|
|
SELECT
|
|
|
|
CASE
|
|
|
|
WHEN NEW.start >= NEW.end THEN
|
|
|
|
RAISE (ABORT, 'start must be before end')
|
|
|
|
END;
|
|
|
|
END;
|