-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathinit.sql
76 lines (68 loc) · 1.98 KB
/
init.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
CREATE TABLE IF NOT EXISTS settings (
name text PRIMARY KEY,
createdDate text NOT NULL,
updatedDate text NOT NULL,
value text NOT NULL
);
CREATE TABLE IF NOT EXISTS messages (
id integer PRIMARY KEY AUTOINCREMENT,
createdDate text NOT NULL,
updatedDate text NOT NULL,
message text NOT NULL,
updateId text NOT NULL
);
CREATE TABLE IF NOT EXISTS initDataCheck (
id integer PRIMARY KEY AUTOINCREMENT,
createdDate text NOT NULL,
updatedDate text NOT NULL,
initData text NOT NULL,
expectedHash text NOT NULL,
calculatedHash text NOT NULL
);
CREATE TABLE IF NOT EXISTS users (
id integer PRIMARY KEY AUTOINCREMENT,
createdDate text NOT NULL,
updatedDate text NOT NULL,
lastAuthTimestamp text NOT NULL,
telegramId integer UNIQUE NOT NULL,
username text,
isBot integer,
firstName text,
lastName text,
languageCode text,
isPremium integer,
addedToAttachmentMenu integer,
allowsWriteToPm integer,
photoUrl text
);
CREATE TABLE IF NOT EXISTS tokens (
id integer PRIMARY KEY AUTOINCREMENT,
createdDate text NOT NULL,
updatedDate text NOT NULL,
expiredDate text NOT NULL,
tokenHash text UNIQUE NOT NULL,
userId integer NOT NULL,
FOREIGN KEY(userId) REFERENCES users(id)
);
CREATE TABLE IF NOT EXISTS calendars (
id integer PRIMARY KEY AUTOINCREMENT,
createdDate text NOT NULL,
updatedDate text NOT NULL,
userId integer NOT NULL,
calendarJson text NOT NULL,
calendarRef text NOT NULL,
FOREIGN KEY(userId) REFERENCES users(id)
);
CREATE TABLE IF NOT EXISTS selectedDates (
id integer PRIMARY KEY AUTOINCREMENT,
createdDate text NOT NULL,
updatedDate text NOT NULL,
userId integer NOT NULL,
calendarId integer NOT NULL,
selectedDatesJson text NOT NULL,
FOREIGN KEY(userId) REFERENCES users(id),
FOREIGN KEY(calendarId) REFERENCES calendars(id)
);
CREATE UNIQUE INDEX IF NOT EXISTS userSelectedDatesIndex ON selectedDates (userId, calendarId);
CREATE UNIQUE INDEX IF NOT EXISTS tokenHashIndex ON tokens (tokenHash);
CREATE UNIQUE INDEX IF NOT EXISTS telegramIdIndex ON users (telegramId);