-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema_sqlite.sql
executable file
·37 lines (33 loc) · 1.24 KB
/
schema_sqlite.sql
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
CREATE TABLE `notes` (
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
`created` TIMESTAMP NOT NULL DEFAULT (strftime('%Y-%m-%d %H:%M:%S', 'now', 'localtime')),
`updated` TIMESTAMP NOT NULL DEFAULT (strftime('%Y-%m-%d %H:%M:%S', 'now', 'localtime')),
`note_title` VARCHAR(255),
`note` TEXT,
`note_markdown` TEXT,
`tags` VARCHAR(200),
`user_id` INTEGER,
FOREIGN KEY(user_id) REFERENCES users(id)
);
CREATE TRIGGER `triggerDate` AFTER UPDATE ON `notes`
BEGIN
update `notes` SET `updated` = (strftime('%Y-%m-%d %H:%M:%S', 'now', 'localtime')) WHERE id = NEW.id;
END;
CREATE TABLE `users` (
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
`registered_at` TIMESTAMP NOT NULL DEFAULT (strftime('%Y-%m-%d %H:%M:%S', 'now', 'localtime')),
`last_login` TIMESTAMP NOT NULL DEFAULT (strftime('%Y-%m-%d %H:%M:%S', 'now', 'localtime')),
`username` VARCHAR(255),
`password` VARCHAR(200),
`email` VARCHAR(200)
);
CREATE TRIGGER `triggerUserLogin` AFTER UPDATE ON `users`
BEGIN
update `users` SET `last_login` = (strftime('%Y-%m-%d %H:%M:%S', 'now', 'localtime')) WHERE id = NEW.id;
END;
CREATE TABLE `tags` (
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
`tag` TEXT,
`user_id` INTEGER,
FOREIGN KEY(user_id) REFERENCES users(id)
);