-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathschema.sql
More file actions
40 lines (29 loc) · 1.63 KB
/
schema.sql
File metadata and controls
40 lines (29 loc) · 1.63 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
DROP TABLE IF EXISTS todos;
CREATE TABLE IF NOT EXISTS todos (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
text TEXT NOT NULL CHECK(length(text) <= 1000),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Index for faster lookups by user_id
CREATE INDEX IF NOT EXISTS idx_todos_user_id ON todos(user_id);
-- Index for sorting by creation time
CREATE INDEX IF NOT EXISTS idx_todos_created_at ON todos(created_at);
-- Index for sorting by update time
CREATE INDEX IF NOT EXISTS idx_todos_updated_at ON todos(updated_at);
-- Compound index for user_id and created_at (useful for getting user's todos sorted by date)
CREATE INDEX IF NOT EXISTS idx_todos_user_created ON todos(user_id, created_at);
INSERT INTO todos (user_id, text, created_at, updated_at)
VALUES (1, 'Complete FastAPI tutorial', '2024-02-13 09:00:00', '2024-02-13 09:00:00');
INSERT INTO todos (user_id, text, created_at, updated_at)
VALUES (1, 'Review pull requests', '2024-02-13 10:30:00', '2024-02-13 11:45:00');
INSERT INTO todos (user_id, text, created_at, updated_at)
VALUES (1, 'Setup database indices', '2024-02-13 14:15:00', '2024-02-13 14:15:00');
-- User 2's todos
INSERT INTO todos (user_id, text, created_at, updated_at)
VALUES (2, 'Update documentation', '2024-02-13 08:45:00', '2024-02-13 09:30:00');
INSERT INTO todos (user_id, text, created_at, updated_at)
VALUES (2, 'Test new features', '2024-02-13 11:00:00', '2024-02-13 11:00:00');
INSERT INTO todos (user_id, text, created_at, updated_at)
VALUES (2, 'Schedule team meeting', '2024-02-13 13:20:00', '2024-02-13 15:45:00');