-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.sql
167 lines (167 loc) · 6.08 KB
/
schema.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS "deck" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
"title" TEXT NOT NULL,
"description" TEXT,
"user_id" INTEGER NOT NULL,
"type" INTEGER NOT NULL,
FOREIGN KEY("user_id") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS "user_match" (
"user_id" INTEGER NOT NULL,
"match_id" INTEGER NOT NULL,
"place" INTEGER NOT NULL,
"deck_id" INTEGER,
PRIMARY KEY("user_id","match_id"),
FOREIGN KEY("user_id") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY("match_id") REFERENCES "match"("id") ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY("deck_id") REFERENCES "deck"("id") ON DELETE SET NULL ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS "match" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
"date" INTEGER NOT NULL,
"type" TEXT NOT NULL,
"title" TEXT
);
CREATE TABLE IF NOT EXISTS "user_group" (
"user_id" INTEGER NOT NULL,
"group_id" INTEGER NOT NULL,
"karma" INTEGER NOT NULL DEFAULT 0,
"points" INTEGER NOT NULL DEFAULT 0,
"lastUp" INTEGER NOT NULL DEFAULT 0,
"lastDown" INTEGER NOT NULL DEFAULT 0,
"lastSuper" INTEGER NOT NULL DEFAULT 0,
"lastReward" INTEGER NOT NULL DEFAULT 0,
PRIMARY KEY("group_id","user_id"),
FOREIGN KEY("user_id") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY("group_id") REFERENCES "group"("id") ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS "user" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
"name" TEXT NOT NULL UNIQUE,
"money" INTEGER NOT NULL DEFAULT 0,
"tgid" INTEGER NOT NULL UNIQUE,
"tgfirstname" TEXT,
"tglastname" TEXT,
"tgusername" TEXT,
"onetime" INTEGER UNIQUE
);
CREATE TABLE IF NOT EXISTS "setting" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
"name" TEXT NOT NULL UNIQUE,
"type" TEXT NOT NULL,
"options" TEXT NOT NULL,
"defaultValue" TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS "transaction" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
"user_id" INTEGER NOT NULL,
"amount" INTEGER NOT NULL,
"purpose" TEXT NOT NULL,
"item_id" INTEGER,
"date" INTEGER NOT NULL,
FOREIGN KEY("item_id") REFERENCES "item"("id") ON DELETE SET NULL ON UPDATE CASCADE,
FOREIGN KEY("user_id") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS "collection" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
"item_id" INTEGER NOT NULL,
"name" TEXT NOT NULL UNIQUE,
FOREIGN KEY("item_id") REFERENCES "item"("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS "shopEntry" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
"item_id" INTEGER NOT NULL UNIQUE,
"price" INTEGER NOT NULL,
"sale" INTEGER,
FOREIGN KEY("item_id") REFERENCES "item"("id") ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS "user_setting" (
"user_id" INTEGER NOT NULL,
"setting_id" INTEGER NOT NULL,
"value" TEXT NOT NULL,
PRIMARY KEY("user_id","setting_id"),
FOREIGN KEY("user_id") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY("setting_id") REFERENCES "setting"("id") ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS "user_role" (
"user_id" INTEGER NOT NULL,
"role_id" INTEGER NOT NULL,
PRIMARY KEY("user_id","role_id"),
FOREIGN KEY("user_id") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY("role_id") REFERENCES "role"("id") ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS "user_item" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
"user_id" INTEGER NOT NULL,
"item_id" INTEGER NOT NULL,
FOREIGN KEY("user_id") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY("item_id") REFERENCES "item"("id") ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS "user_award" (
"user_id" INTEGER NOT NULL,
"award_id" INTEGER NOT NULL,
"date" INTEGER NOT NULL,
PRIMARY KEY("user_id","award_id"),
FOREIGN KEY("user_id") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY("award_id") REFERENCES "award"("id") ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS "role_permission" (
"role_id" INTEGER NOT NULL,
"permission_id" INTEGER NOT NULL,
PRIMARY KEY("role_id","permission_id"),
FOREIGN KEY("role_id") REFERENCES "role"("id") ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY("permission_id") REFERENCES "permission"("id") ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS "item_collection" (
"item_id" INTEGER NOT NULL,
"collection_id" INTEGER NOT NULL,
"chance" INTEGER,
PRIMARY KEY("collection_id","item_id"),
FOREIGN KEY("item_id") REFERENCES "item"("id") ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY("collection_id") REFERENCES "collection"("id") ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS "group_setting" (
"group_id" INTEGER NOT NULL,
"setting_id" INTEGER NOT NULL,
"value" TEXT NOT NULL,
PRIMARY KEY("group_id","setting_id"),
FOREIGN KEY("group_id") REFERENCES "group"("id") ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY("setting_id") REFERENCES "setting"("id") ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS "item" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
"name" TEXT NOT NULL UNIQUE,
"description" TEXT,
"icon" TEXT,
"rarity" INTEGER
);
CREATE TABLE IF NOT EXISTS "award" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
"title" TEXT NOT NULL UNIQUE,
"description" TEXT,
"icon" TEXT
);
CREATE TABLE IF NOT EXISTS "token" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
"user_id" INTEGER NOT NULL,
"text" TEXT NOT NULL UNIQUE,
"app" TEXT NOT NULL,
FOREIGN KEY("text") REFERENCES "user"("id")
);
CREATE TABLE IF NOT EXISTS "role" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
"name" INTEGER NOT NULL UNIQUE
);
CREATE TABLE IF NOT EXISTS "permission" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
"name" TEXT NOT NULL UNIQUE,
"description" TEXT
);
CREATE TABLE IF NOT EXISTS "group" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
"tgid" INTEGER NOT NULL UNIQUE,
"type" TEXT,
"title" TEXT NOT NULL
);
COMMIT;