home · contact · privacy
Clean up enablers/disablers code and naming conventions.
[plomtask] / scripts / init.sql
index 807e1e7a0fc06b3da97204e99a23b2342306272a..b2979a5e1dffeedf0445ef65e6a675ec50e9bfce 100644 (file)
@@ -1,23 +1,23 @@
 CREATE TABLE condition_descriptions (
-    parent_id INTEGER NOT NULL,
+    parent INTEGER NOT NULL,
     timestamp TEXT NOT NULL,
     description TEXT NOT NULL,
-    PRIMARY KEY (parent_id, timestamp),
-    FOREIGN KEY (parent_id) REFERENCES conditions(id)
+    PRIMARY KEY (parent, timestamp),
+    FOREIGN KEY (parent) REFERENCES conditions(id)
 );
 CREATE TABLE condition_titles (
-    parent_id INTEGER NOT NULL,
+    parent INTEGER NOT NULL,
     timestamp TEXT NOT NULL,
     title TEXT NOT NULL,
-    PRIMARY KEY (parent_id, timestamp),
-    FOREIGN KEY (parent_id) REFERENCES conditions(id)
+    PRIMARY KEY (parent, timestamp),
+    FOREIGN KEY (parent) REFERENCES conditions(id)
 );
 CREATE TABLE conditions (
     id INTEGER PRIMARY KEY,
     is_active BOOLEAN NOT NULL
 );
 CREATE TABLE days (
-    date TEXT PRIMARY KEY,
+    id TEXT PRIMARY KEY,
     comment TEXT NOT NULL
 );
 CREATE TABLE process_conditions (
@@ -28,20 +28,27 @@ CREATE TABLE process_conditions (
     FOREIGN KEY (condition) REFERENCES conditions(id)
 );
 CREATE TABLE process_descriptions (
-    parent_id INTEGER NOT NULL,
+    parent INTEGER NOT NULL,
     timestamp TEXT NOT NULL,
     description TEXT NOT NULL,
-    PRIMARY KEY (parent_id, timestamp),
-    FOREIGN KEY (parent_id) REFERENCES processes(id)
+    PRIMARY KEY (parent, timestamp),
+    FOREIGN KEY (parent) REFERENCES processes(id)
+);
+CREATE TABLE process_disables (
+    process INTEGER NOT NULL,
+    condition INTEGER NOT NULL,
+    PRIMARY KEY(process, condition),
+    FOREIGN KEY (process) REFERENCES processes(id),
+    FOREIGN KEY (condition) REFERENCES conditions(id)
 );
 CREATE TABLE process_efforts (
-    parent_id INTEGER NOT NULL,
+    parent INTEGER NOT NULL,
     timestamp TEXT NOT NULL,
     effort REAL NOT NULL,
-    PRIMARY KEY (parent_id, timestamp),
-    FOREIGN KEY (parent_id) REFERENCES processes(id)
+    PRIMARY KEY (parent, timestamp),
+    FOREIGN KEY (parent) REFERENCES processes(id)
 );
-CREATE TABLE process_fulfills (
+CREATE TABLE process_enables (
     process INTEGER NOT NULL,
     condition INTEGER NOT NULL,
     PRIMARY KEY(process, condition),
@@ -49,27 +56,20 @@ CREATE TABLE process_fulfills (
     FOREIGN KEY (condition) REFERENCES conditions(id)
 );
 CREATE TABLE process_steps (
-    step_id INTEGER PRIMARY KEY,
-    owner_id INTEGER NOT NULL,
-    step_process_id INTEGER NOT NULL,
-    parent_step_id INTEGER,
-    FOREIGN KEY (owner_id) REFERENCES processes(id),
-    FOREIGN KEY (step_process_id) REFERENCES processes(id),
-    FOREIGN KEY (parent_step_id) REFERENCES process_steps(step_id)
+    id INTEGER PRIMARY KEY,
+    owner INTEGER NOT NULL,
+    step_process INTEGER NOT NULL,
+    parent_step INTEGER,
+    FOREIGN KEY (owner) REFERENCES processes(id),
+    FOREIGN KEY (step_process) REFERENCES processes(id),
+    FOREIGN KEY (parent_step) REFERENCES process_steps(step_id)
 );
 CREATE TABLE process_titles (
-    parent_id INTEGER NOT NULL,
+    parent INTEGER NOT NULL,
     timestamp TEXT NOT NULL,
     title TEXT NOT NULL,
-    PRIMARY KEY (parent_id, timestamp),
-    FOREIGN KEY (parent_id) REFERENCES processes(id)
-);
-CREATE TABLE process_undoes (
-    process INTEGER NOT NULL,
-    condition INTEGER NOT NULL,
-    PRIMARY KEY(process, condition),
-    FOREIGN KEY (process) REFERENCES processes(id),
-    FOREIGN KEY (condition) REFERENCES conditions(id)
+    PRIMARY KEY (parent, timestamp),
+    FOREIGN KEY (parent) REFERENCES processes(id)
 );
 CREATE TABLE processes (
     id INTEGER PRIMARY KEY
@@ -88,14 +88,14 @@ CREATE TABLE todo_conditions (
     FOREIGN KEY (todo) REFERENCES todos(id),
     FOREIGN KEY (condition) REFERENCES conditions(id)
 );
-CREATE TABLE todo_fulfills (
+CREATE TABLE todo_disables (
     todo INTEGER NOT NULL,
     condition INTEGER NOT NULL,
     PRIMARY KEY(todo, condition),
     FOREIGN KEY (todo) REFERENCES todos(id),
     FOREIGN KEY (condition) REFERENCES conditions(id)
 );
-CREATE TABLE todo_undoes (
+CREATE TABLE todo_enables (
     todo INTEGER NOT NULL,
     condition INTEGER NOT NULL,
     PRIMARY KEY(todo, condition),
@@ -104,9 +104,9 @@ CREATE TABLE todo_undoes (
 );
 CREATE TABLE todos (
     id INTEGER PRIMARY KEY,
-    process_id INTEGER NOT NULL,
+    process INTEGER NOT NULL,
     is_done BOOLEAN NOT NULL,
     day TEXT NOT NULL,
-    FOREIGN KEY (process_id) REFERENCES processes(id),
-    FOREIGN KEY (day) REFERENCES days(date)
+    FOREIGN KEY (process) REFERENCES processes(id),
+    FOREIGN KEY (day) REFERENCES days(id)
 );