aboutsummaryrefslogtreecommitdiff
path: root/src/main/resources/schema-sqlite.sql
blob: 2b32635ed83736576bde30f3688982f10b0bb69b (plain) (blame)
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
PRAGMA journal_mode=WAL;
PRAGMA busy_timeout=30000;
CREATE TABLE user_services (
    user_id INTEGER NOT NULL,
    regid character varying(1024) NOT NULL,
    ts DEFAULT (strftime('%s','now') || substr(strftime('%f','now'),4)) NOT NULL,
    service_type varchar(255) not null default 'fcm',
    FOREIGN KEY (user_id) REFERENCES users(id),
    UNIQUE (regid)
);
CREATE TABLE auth (
    user_id INTEGER,
    protocol TEXT CHECK (protocol IN ('xmpp', 'email', 'sms')) NOT NULL,
    account character varying(128) NOT NULL,
    authcode character varying(8) NOT NULL,
    ts DEFAULT (strftime('%s','now') || substr(strftime('%f','now'),4)) NOT NULL,
    FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE bl_tags (
    user_id INTEGER NOT NULL,
    tag_id bigint NOT NULL,
    FOREIGN KEY (user_id) REFERENCES users(id),
    FOREIGN KEY (tag_id) REFERENCES tags(tag_id)
);
CREATE TABLE bl_users (
    user_id INTEGER NOT NULL,
    bl_user_id bigint NOT NULL,
    ts DEFAULT (strftime('%s','now') || substr(strftime('%f','now'),4)) NOT NULL,
    PRIMARY KEY (user_id, bl_user_id),
    FOREIGN KEY (user_id) REFERENCES users(id),
    FOREIGN KEY (bl_user_id) REFERENCES users(id)
);
CREATE TABLE emails (
    user_id INTEGER NOT NULL,
    email character varying(128) NOT NULL,
    subscr_hour smallint,
    FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE facebook (
    user_id INTEGER,
    fb_id numeric,
    loginhash character varying(36),
    access_token character varying(255),
    ts DEFAULT (strftime('%s','now') || substr(strftime('%f','now'),4)) NOT NULL,
    fb_name character varying(64),
    fb_link character varying(255) NOT NULL,
    crosspost boolean DEFAULT true NOT NULL,
    FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE favorites (
    user_id INTEGER NOT NULL,
    message_id bigint NOT NULL,
    ts timestamp with time zone,
    like_id smallint DEFAULT 1 NOT NULL,
    user_uri character varying(255) NOT NULL DEFAULT '',
    FOREIGN KEY (like_id) REFERENCES reactions(like_id)
);
CREATE TABLE followers (
    user_id INTEGER,
    ts DEFAULT (strftime('%s','now') || substr(strftime('%f','now'),4)) NOT NULL,
    acct character varying(64) NOT NULL,
    PRIMARY KEY (user_id)
    FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE jids (
    user_id INTEGER,
    jid character varying(64) NOT NULL,
    active smallint DEFAULT 0 NOT NULL,
    loginhash character varying(36),
    ts DEFAULT (strftime('%s','now') || substr(strftime('%f','now'),4)) NOT NULL,
    FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE logins (
    user_id INTEGER NOT NULL,
    hash character varying(16) NOT NULL,
    FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE meon (
    id INTEGER NOT NULL,
    user_id INTEGER NOT NULL,
    link character varying(255) NOT NULL,
    name character varying(32) NOT NULL,
    ico smallint,
    FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE messages (
    message_id INTEGER PRIMARY KEY NOT NULL,
    user_id INTEGER NOT NULL,
    lang TEXT DEFAULT '__' NOT NULL,
    ts DEFAULT (strftime('%s','now') || substr(strftime('%f','now'),4)) NOT NULL,
    replies smallint DEFAULT (0) NOT NULL,
    maxreplyid smallint DEFAULT (0) NOT NULL,
    privacy smallint DEFAULT (1) NOT NULL,
    readonly boolean DEFAULT false NOT NULL,
    attach TEXT CHECK (attach IN ('jpg', 'mp4', 'png')),
    place_id bigint,
    lat numeric(10,7),
    lon numeric(10,7),
    popular smallint DEFAULT (0) NOT NULL,
    hidden smallint DEFAULT (0) NOT NULL,
    likes smallint DEFAULT (0) NOT NULL,
    updated DEFAULT (strftime('%s','now') || substr(strftime('%f','now'),4)) NOT NULL,
    repliesby text,
    txt text NOT NULL,
    updated_at DEFAULT (strftime('%s','now') || substr(strftime('%f','now'),4)) NOT NULL,
    FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE messages_access (
    message_id INTEGER NOT NULL,
    user_id INTEGER NOT NULL,
    FOREIGN KEY (user_id) REFERENCES users(id),
    FOREIGN KEY (message_id) REFERENCES messages(message_id)
);
CREATE TABLE messages_properties (
    message_id INTEGER NOT NULL,
    reply_id smallint NOT NULL,
    property_key character varying(255) NOT NULL,
    property_value text NOT NULL,
    UNIQUE (message_id, reply_id, property_key),
    FOREIGN KEY (message_id) REFERENCES messages(message_id)
);
CREATE TABLE messages_tags (
    message_id INTEGER NOT NULL,
    tag_id bigint NOT NULL,
    FOREIGN KEY (message_id) REFERENCES messages(message_id)
);
CREATE TABLE places (
    place_id INTEGER PRIMARY KEY NOT NULL,
    lat numeric(10,7) NOT NULL,
    lon numeric(10,7) NOT NULL,
    name character varying(64) NOT NULL,
    descr character varying(255),
    url character varying(128),
    user_id bigint NOT NULL,
    ts DEFAULT (strftime('%s','now') || substr(strftime('%f','now'),4)) NOT NULL
);
CREATE TABLE places_tags (
    place_id INTEGER NOT NULL,
    tag_id bigint NOT NULL,
    FOREIGN KEY (place_id) REFERENCES places(place_id)
);
CREATE TABLE pm (
    user_id INTEGER NOT NULL,
    user_id_to INTEGER NOT NULL,
    ts DEFAULT (strftime('%s','now') || substr(strftime('%f','now'),4)) NOT NULL,
    txt text NOT NULL,
    FOREIGN KEY (user_id) REFERENCES users(id),
    FOREIGN KEY (user_id_to) REFERENCES users(id)
);
CREATE TABLE reactions (
    like_id INTEGER PRIMARY KEY NOT NULL,
    description character varying(100) NOT NULL
);
CREATE TABLE replies (
    message_id bigint NOT NULL,
    reply_id smallint NOT NULL,
    user_id INTEGER NOT NULL,
    replyto smallint DEFAULT (0) NOT NULL,
    ts DEFAULT (strftime('%s','now') || substr(strftime('%f','now'),4)) NOT NULL,
    attach TEXT CHECK (attach IN ('jpg', 'mp4', 'png')),
    txt text NOT NULL,
    updated_at DEFAULT CURRENT_TIMESTAMP NOT NULL,
    user_uri character varying(255) DEFAULT NULL,
    reply_uri character varying(255) DEFAULT NULL,
    html smallint DEFAULT '0' NOT NULL,
    FOREIGN KEY (message_id) REFERENCES messages(message_id),
    FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE subscr_messages (
    message_id bigint NOT NULL,
    suser_id INTEGER NOT NULL,
    last_read_rid smallint DEFAULT 0 NOT NULL,
    FOREIGN KEY (message_id) REFERENCES messages(message_id),
    FOREIGN KEY (suser_id) REFERENCES users(id)
);
CREATE TABLE subscr_tags (
    tag_id bigint NOT NULL,
    suser_id INTEGER NOT NULL,
    FOREIGN KEY (tag_id) REFERENCES tags(tag_id),
    FOREIGN KEY (suser_id) REFERENCES users(id)
);
CREATE TABLE subscr_users (
    user_id INTEGER NOT NULL,
    suser_id INTEGER NOT NULL,
    ts DEFAULT (strftime('%s','now') || substr(strftime('%f','now'),4)) NOT NULL,
    FOREIGN KEY (user_id) REFERENCES users(id),
    FOREIGN KEY (suser_id) REFERENCES users(id)
);
CREATE TABLE tags (
    tag_id INTEGER PRIMARY KEY NOT NULL,
    synonym_id bigint,
    name character varying(70) COLLATE NOCASE,
    notop smallint DEFAULT 0 NOT NULL,
    noindex smallint DEFAULT 0 NOT NULL,
    stat_messages bigint DEFAULT (0) NOT NULL,
    stat_users smallint DEFAULT (0) NOT NULL,
    FOREIGN KEY (synonym_id) REFERENCES tags(tag_id)
);
CREATE TABLE tags_ignore (
    tag_id bigint NOT NULL,
    FOREIGN KEY (tag_id) REFERENCES tags(tag_id)
);
CREATE TABLE telegram (
    user_id INTEGER,
    tg_id numeric NOT NULL,
    tg_name character varying(64) NOT NULL,
    ts DEFAULT (strftime('%s','now') || substr(strftime('%f','now'),4)) NOT NULL,
    loginhash character varying(36),
    FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE twitter (
    user_id INTEGER NOT NULL,
    access_token character varying(64) NOT NULL,
    access_token_secret character varying(64) NOT NULL,
    uname character varying(64) NOT NULL,
    ts DEFAULT (strftime('%s','now') || substr(strftime('%f','now'),4)) NOT NULL,
    crosspost boolean DEFAULT true NOT NULL,
    FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE users (
    id INTEGER PRIMARY KEY,
    nick character varying(64) NOT NULL COLLATE NOCASE,
    passw character varying(32) NOT NULL,
    lang users_lang DEFAULT '__' NOT NULL,
    banned smallint DEFAULT (0) NOT NULL,
    lastmessage timestamp with time zone,
    lastpm bigint DEFAULT (0) NOT NULL,
    lastphoto bigint DEFAULT (0) NOT NULL,
    karma smallint DEFAULT (0) NOT NULL,
    premium smallint DEFAULT (0) NOT NULL,
    last_seen timestamp with time zone,
    UNIQUE(nick)
);
CREATE TABLE usersinfo (
    user_id INTEGER NOT NULL,
    jid character varying(64),
    fullname character varying(64),
    country character varying(32),
    url character varying(128),
    gender character varying(32),
    bday character varying(32),
    descr text,
    UNIQUE(user_id),
    FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE vk (
    user_id INTEGER,
    vk_id numeric NULL,
    loginhash character varying(36),
    access_token character varying(128) NOT NULL,
    ts DEFAULT (strftime('%s','now') || substr(strftime('%f','now'),4)) NOT NULL,
    vk_name character varying(64) NOT NULL,
    vk_link character varying(64) NOT NULL,
    crosspost smallint DEFAULT (1) NOT NULL,
    FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE wl_users (
    user_id INTEGER NOT NULL,
    wl_user_id bigint NOT NULL,
    PRIMARY KEY (user_id, wl_user_id),
    FOREIGN KEY (user_id) REFERENCES users(id),
    FOREIGN KEY (wl_user_id) REFERENCES users(id)
);
CREATE TABLE oauth2_registered_client (
    id varchar(100) NOT NULL,
    client_id varchar(100) NOT NULL,
    client_id_issued_at timestamp DEFAULT (strftime('%s','now') || substr(strftime('%f','now'),4)) NOT NULL,
    client_secret varchar(200) DEFAULT NULL,
    client_secret_expires_at timestamp DEFAULT NULL,
    client_name varchar(200) NOT NULL,
    client_authentication_methods varchar(1000) NOT NULL,
    authorization_grant_types varchar(1000) NOT NULL,
    redirect_uris varchar(1000) DEFAULT NULL,
    post_logout_redirect_uris varchar(1000) DEFAULT NULL,
    scopes varchar(1000) NOT NULL,
    client_settings varchar(2000) NOT NULL,
    token_settings varchar(2000) NOT NULL,
    PRIMARY KEY (id)
);