Initial commit.
[todo.git] / todo-schema.sql
1 -- PostgreSQL database schema.
2
3 begin work;
4
5 -- List of all tasks.
6 --
7 -- Note that unsorted tasks (which need to be moved to 'imminent',
8 -- 'todo', 'ideas', 'retired' lists) are any item which appears in
9 -- this table but not in one of the other tables.
10 create table tasks (
11     id serial not null primary key,
12     description text not null,
13     created timestamp without time zone not null default now(),
14
15     -- task source
16     rhbz integer,               -- if task comes from RHBZ
17     message_id text             -- if task comes from email
18 );
19
20 -- Tasks which must be completed immediately and should take no more
21 -- than a few minutes (else they should be moved to another list).
22 create table imminent (
23     taskid integer not null references tasks (id),
24     added timestamp without time zone not null default now()
25 );
26
27 -- Regular to-do items with deadlines.
28 create table todo (
29     taskid integer not null references tasks (id),
30     added timestamp without time zone not null default now(),
31     deadline timestamp without time zone not null,
32     estimate interval           -- optional
33 );
34
35 -- Ideas.  These have no committed deadline.
36 create table ideas (
37     taskid integer not null references tasks (id),
38     added timestamp without time zone not null default now()
39 );
40
41 -- Retired/done items.
42 create table retired (
43     taskid integer not null references tasks (id),
44     added timestamp without time zone not null default now()
45 );
46
47 -- Tags (eg 'urgent', 'personal', 'work') which can be added to any
48 -- task.
49 create table tags (
50     id serial not null primary key,
51     name text not null,
52     colour text not null references colours (colour)
53 );
54
55 create table tags_tasks (
56     tagid integer not null references tags (id),
57     taskid integer not null references tasks (id)
58 );
59
60 create table colours (
61     colour text not null,
62     unique (colour)
63 );
64 insert into colours (colour) values ('black');
65 insert into colours (colour) values ('blue');
66 insert into colours (colour) values ('green');
67 insert into colours (colour) values ('red');
68 insert into colours (colour) values ('purple');
69 insert into colours (colour) values ('cyan');
70 insert into colours (colour) values ('yellow');
71
72 commit;