-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery.sql
More file actions
70 lines (63 loc) · 2.42 KB
/
Copy pathquery.sql
File metadata and controls
70 lines (63 loc) · 2.42 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
-- -- Table for users (already exists)
-- CREATE TABLE IF NOT EXISTS users (
-- id INTEGER PRIMARY KEY AUTOINCREMENT,
-- username TEXT UNIQUE NOT NULL,
-- email TEXT UNIQUE NOT NULL,
-- password TEXT NOT NULL
-- );
-- -- Table for groups
-- CREATE TABLE IF NOT EXISTS groups (
-- id INTEGER PRIMARY KEY AUTOINCREMENT,
-- name TEXT NOT NULL,
-- owner_id INTEGER NOT NULL,
-- FOREIGN KEY (owner_id) REFERENCES users(id)
-- );
-- -- Table for group members (user's relationship with groups)
-- CREATE TABLE IF NOT EXISTS group_members (
-- group_id INTEGER NOT NULL,
-- user_id INTEGER NOT NULL,
-- FOREIGN KEY (group_id) REFERENCES groups(id),
-- FOREIGN KEY (user_id) REFERENCES users(id),
-- PRIMARY KEY (group_id, user_id)
-- );
-- -- Table for tasks
-- CREATE TABLE IF NOT EXISTS tasks (
-- id INTEGER PRIMARY KEY AUTOINCREMENT,
-- name TEXT NOT NULL,
-- description TEXT NOT NULL,
-- due_date TEXT NOT NULL,
-- priority INTEGER NOT NULL, -- Enum mapped to integer
-- status INTEGER NOT NULL, -- Enum mapped to integer
-- group_id INTEGER NOT NULL,
-- FOREIGN KEY (group_id) REFERENCES groups(id)
-- );
-- SELECT * FROM groups;
-- CREATE TABLE tasks (
-- id INTEGER PRIMARY KEY AUTOINCREMENT,
-- name TEXT NOT NULL,
-- description TEXT,
-- due_date INTEGER NOT NULL,
-- priority INTEGER NOT NULL, -- 1 = Low, 2 = Medium, 3 = High
-- status INTEGER NOT NULL DEFAULT 0, -- 0 = Pending, 1 = In Progress, 2 = Completed
-- group_id INTEGER NOT NULL,
-- creator_id INTEGER NOT NULL, -- Links to users table
-- creator_name TEXT NOT NULL, -- Store the creator's name directly
-- FOREIGN KEY (group_id) REFERENCES groups(id) ON DELETE CASCADE,
-- FOREIGN KEY (creator_id) REFERENCES users(userId) ON DELETE CASCADE
-- );
-- CREATE TABLE tasks_new (
-- id INTEGER PRIMARY KEY AUTOINCREMENT,
-- name TEXT NOT NULL,
-- description TEXT,
-- due_date INTEGER NOT NULL, -- Changed from TEXT to INTEGER
-- priority INTEGER NOT NULL,
-- status INTEGER NOT NULL DEFAULT 0,
-- group_id INTEGER NOT NULL,
-- creator_id INTEGER NOT NULL,
-- creator_name TEXT NOT NULL,
-- FOREIGN KEY (group_id) REFERENCES groups(id) ON DELETE CASCADE,
-- FOREIGN KEY (creator_id) REFERENCES users(userId) ON DELETE CASCADE
-- );
SELECT g.id, g.name FROM groups g
JOIN group_members gm ON g.id = gm.group_id
WHERE gm.user_id = 6;