-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
32 lines (28 loc) · 783 Bytes
/
Copy pathschema.sql
File metadata and controls
32 lines (28 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS projects;
DROP TABLE IF EXISTS documents;
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT UNIQUE NOT NULL,
password TEXT NOT NULL
);
CREATE TABLE projects (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
description TEXT,
user_id INTEGER NOT NULL, progress INTEGER DEFAULT 0,
FOREIGN KEY(user_id) REFERENCES users(id)
);
CREATE TABLE documents (
id INTEGER PRIMARY KEY AUTOINCREMENT,
filename TEXT NOT NULL,
project_id INTEGER NOT NULL,
FOREIGN KEY(project_id) REFERENCES projects(id)
);
CREATE TRIGGER delete_duplicate_before_insert
BEFORE INSERT ON documents
FOR EACH ROW
BEGIN
DELETE FROM documents
WHERE filename = NEW.filename;
END;