-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusers.sql
105 lines (85 loc) · 2.81 KB
/
users.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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
CREATE TABLE IF NOT EXISTS `users` (
`id` TEXT PRIMARY KEY,
`json` TEXT,
`hash` TEXT,
`timestamp` DATETIME DEFAULT CURRENT_TIMESTAMP,
`username` TEXT as (json_extract(`json`,'$.username')) STORED UNIQUE,
`email` TEXT as (json_extract(`json`,'$.email')) STORED UNIQUE,
`password` TEXT as (json_extract(`json`,'$.password')) STORED,
`picture` TEXT as (json_extract(`json`,'$.picture')) STORED,
`phone` TEXT as (json_extract(`json`,'$.phone')) STORED UNIQUE
);
-- Indexes for table `users`
CREATE INDEX IF NOT EXISTS `idx_hash` ON users(`hash`);
CREATE INDEX IF NOT EXISTS `idx_username` ON users(`username`);
CREATE INDEX IF NOT EXISTS `idx_email` ON users(`email`);
--
CREATE TABLE IF NOT EXISTS `users_log` (
`id` TEXT PRIMARY KEY,
`userId` TEXT,
`json` TEXT,
`hash` TEXT,
`timestamp` DATETIME DEFAULT CURRENT_TIMESTAMP
);
-- Indexes for `users_log`
CREATE INDEX IF NOT EXISTS `idx_userId` ON users_log(`userId`);
CREATE INDEX IF NOT EXISTS `idx_hash` ON users_log(`hash`);
--
CREATE TABLE IF NOT EXISTS `auth` (
`id` TEXT PRIMARY KEY,
`userId` TEXT,
`json` TEXT,
`hash` TEXT,
`timestamp` DATETIME DEFAULT CURRENT_TIMESTAMP,
`token` TEXT as (json_extract(`json`,'$.token')) STORED UNIQUE,
`validated` TEXT as (json_extract(`json`,'$.validated')) STORED,
`emailCode` TEXT as (json_extract(`json`,'$.emailCode')) STORED,
`phoneCode` TEXT as (json_extract(`json`,'$.phoneCode')) STORED,
`device` TEXT as (json_extract(`json`,'$.device')) STORED,
`ip` TEXT as (json_extract(`json`,'$.ip')) STORED,
`location` TEXT as (json_extract(`json`,'$.location')) STORED
);
-- Indexes for `auth`
CREATE INDEX IF NOT EXISTS `idx_userId` ON auth(`userId`);
CREATE INDEX IF NOT EXISTS `idx_token` ON auth(`token`);
--
CREATE TABLE IF NOT EXISTS `auth_log` (
`id` TEXT PRIMARY KEY,
`userId` TEXT,
`json` TEXT,
`hash` TEXT,
`timestamp` DATETIME DEFAULT CURRENT_TIMESTAMP
);
-- Indexes for `auth_log`
CREATE INDEX IF NOT EXISTS `idx_userId` ON auth_log(`userId`);
CREATE INDEX IF NOT EXISTS `idx_hash` ON auth_log(`hash`);
--
CREATE TABLE IF NOT EXISTS `refresh` (
`id` TEXT PRIMARY KEY,
`userId` TEXT,
`authId` TEXT,
`json` TEXT,
`hash` TEXT,
`timestamp` DATETIME DEFAULT CURRENT_TIMESTAMP,
`token` TEXT UNIQUE,
`validated` TEXT,
`emailCode` TEXT,
`phoneCode` TEXT,
`device` TEXT,
`ip` TEXT,
`location` TEXT
);
-- Indexes for `refresh`
CREATE INDEX IF NOT EXISTS `idx_userId` ON refresh(`userId`);
CREATE INDEX IF NOT EXISTS `idx_token` ON refresh(`token`);
--
CREATE TABLE IF NOT EXISTS `refresh_log` (
`id` TEXT PRIMARY KEY,
`userId` TEXT,
`json` TEXT,
`hash` TEXT,
`timestamp` DATETIME DEFAULT CURRENT_TIMESTAMP
);
-- Indexes for `refresh_log`
CREATE INDEX IF NOT EXISTS `idx_userId` ON refresh_log(`userId`);
CREATE INDEX IF NOT EXISTS `idx_hash` ON refresh_log(`hash`);