-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageServer.sql
More file actions
92 lines (84 loc) · 2.74 KB
/
ImageServer.sql
File metadata and controls
92 lines (84 loc) · 2.74 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
-- ######################################
-- ## Database Schema of Image Server ##
-- ######################################
-- Scripted by : Dibesh Raj Subedi
-- Schema Version: 1.0.0
-- Created At: 06/03/2022
-- Updated At: 06/03/2022
-- ######################################
-- Users Table
-- Creating `users` Table
CREATE TABLE
IF NOT EXISTS users (
UserId INTEGER PRIMARY KEY AUTOINCREMENT,
UserName VARCHAR(16) NOT NULL UNIQUE,
FullName VARCHAR(200) NOT NULL,
Email TEXT NOT NULL UNIQUE,
PASSWORD TEXT NOT NULL,
IsLoggedIn BOOLEAN NOT NULL DEFAULT 0,
UserGroup VARCHAR(20) NOT NULL DEFAULT 'USER',
IsDisabled BOOLEAN NOT NULL DEFAULT 1,
VerificationToken TEXT NULL,
LastPasswordResetDate DATETIME NULL DEFAULT (DATETIME('now', 'localtime')),
VerificationStatus BOOLEAN NOT NULL DEFAULT 0,
CreatedAt DATETIME DEFAULT (DATETIME('now', 'localtime')),
UpdatedAt DATETIME NULL
);
-- Creating `user_update_at_trigger` Trigger
CREATE TRIGGER
IF NOT EXISTS users_updated_at_trigger AFTER
UPDATE
ON users BEGIN
UPDATE users
SET UpdatedAt = (DATETIME('now', 'localtime'))
WHERE UserId = NEW.UserId;
END;
-- Old Password Table
-- Creating `old_passwords` Table
CREATE TABLE
IF NOT EXISTS old_passwords (
PasswordId INTEGER PRIMARY KEY AUTOINCREMENT,
UserId INTEGER NOT NULL,
ResetToken TEXT NULL,
HashedPassword TEXT NOT NULL,
ResetSuccess BOOLEAN NOT NULL DEFAULT 0,
HasExpired BOOLEAN NOT NULL DEFAULT 0,
CreatedAt DATETIME DEFAULT (DATETIME('now', 'localtime')),
UpdatedAt DATETIME NULL,
CONSTRAINT fk_user_password FOREIGN KEY (UserId) REFERENCES users (UserId)
ON
DELETE CASCADE
);
-- Creating `password_update_at_trigger` Trigger
CREATE TRIGGER
IF NOT EXISTS password_update_at_trigger AFTER
UPDATE
ON old_passwords BEGIN
UPDATE old_passwords
SET UpdatedAt = (DATETIME('now', 'localtime'))
WHERE PasswordId = NEW.PasswordId;
END;
-- Images Table
-- Creating `images` Table
CREATE TABLE
IF NOT EXISTS image (
ImageId INTEGER PRIMARY KEY AUTOINCREMENT,
UserId INTEGER NOT NULL,
FileName TEXT NOT NULL UNIQUE,
Extension VARCHAR(10) NOT NULL,
FilePath TEXT NOT NULL,
FileSize INTEGER NOT NULL,
UploadDate DATETIME DEFAULT (DATETIME('now', 'localtime')),
CONSTRAINT fk_user_image FOREIGN KEY (UserId) REFERENCES users (UserId)
ON
DELETE CASCADE
);
-- Creating `uploaddate_update_at_trigger` Trigger
CREATE TRIGGER
IF NOT EXISTS uploaddate_update_at_trigger AFTER
UPDATE
ON image BEGIN
UPDATE image
SET UploadDate = (DATETIME('now', 'localtime'))
WHERE ImageId = NEW.ImageId;
END;