63 lines
2.5 KiB
SQL
63 lines
2.5 KiB
SQL
-- schema.sql
|
|
|
|
-- Schema for pit in python / SQLite mode
|
|
-- v0.1
|
|
|
|
CREATE TABLE project (
|
|
id integer primary key,
|
|
username text, -- User the project belongs to.
|
|
name text, -- Project name.
|
|
status text, -- Project status.
|
|
--number_of_tasks integer, -- Number of tasks for the project.
|
|
created_at date, -- When the project was created?
|
|
updatet_at date -- When the project was last updated?
|
|
);
|
|
|
|
CREATE TABLE task (
|
|
id integer primary key, -- TODO When delete, counter go down ==> problem?? Use autoincrement?
|
|
project_id integer, -- Which project the task belongs to?
|
|
username text, -- User the task belongs to.
|
|
name text, -- Task name.
|
|
status text, -- Task status.
|
|
priority text, -- Task priority.
|
|
date date, -- Generic date/time, ex: task deadline.
|
|
time date, -- Generic time, ex: time spent on the task.
|
|
-- number_of_notes integer, -- Number of notes for the task.
|
|
created_at date, -- When the task was created?
|
|
updated_at date -- When the task was last updated?
|
|
);
|
|
|
|
-- CREATE TRIGGER insert_task AFTER INSERT ON task
|
|
-- BEGIN
|
|
-- UPDATE project SET number_of_tasks = (SELECT count(*) FROM task WHERE project_id = new.project_id) WHERE id = new.project_id;
|
|
-- END;
|
|
|
|
-- CREATE TRIGGER delete_task AFTER DELETE ON task
|
|
-- BEGIN
|
|
-- UPDATE project SET number_of_tasks = (SELECT count(*) FROM task WHERE project_id = old.project_id) WHERE id = old.project_id;
|
|
-- END;
|
|
|
|
CREATE TABLE note (
|
|
id integer primary key,
|
|
project_id integer, -- Project the note belongs to (0 if belongs to task).
|
|
task_id integer, -- Task the note belongs to (0 if belongs to project).
|
|
username text, -- User who created the note.
|
|
message text, -- The body of the note.
|
|
created_at date, -- When the note was created?
|
|
updated_at date -- When the note was last updated?
|
|
);
|
|
|
|
CREATE TABLE action (
|
|
id integer primary key,
|
|
project_id integer, -- Project id (always set).
|
|
task_id integer, -- Task id (set for task or note related actions).
|
|
note_id integer, -- Note id (set for note related actions only).
|
|
username text, -- Who added the log message?
|
|
message text, -- Log message.
|
|
created_at date -- When log message was added?
|
|
);
|
|
|
|
CREATE TRIGGER action_insert_created_at AFTER INSERT ON action
|
|
BEGIN
|
|
UPDATE action SET created_at = strftime('%Y-%m-%d %H:%M:%S.%s', 'now', 'localtime') WHERE id = new.id;
|
|
END |