-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.sql
60 lines (52 loc) · 1.5 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
-- CREATE DATABASE tgclient;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TABLE message (
id SERIAL PRIMARY KEY,
uuid UUID NOT NULL UNIQUE,
message BIGINT,
chatid BIGINT NOT NULL,
groupid BIGINT,
platform TEXT,
fileid TEXT,
time_creation TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE settings (
id SERIAL PRIMARY KEY,
chatid BIGINT NOT NULL,
tgchatid BIGINT,
vkchatid BIGINT,
username JSONB,
should_create BOOLEAN DEFAULT TRUE,
firstmessageid BIGINT,
time_creation TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS userstat (
id SERIAL PRIMARY KEY,
chatid BIGINT NOT NULL UNIQUE,
bayan JSONB NOT NULL,
time_creation TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
last_update TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS errors (
id SERIAL PRIMARY KEY,
key UUID DEFAULT uuid_generate_v4(),
chatid BIGINT NOT NULL,
userid BIGINT NOT NULL,
platform TEXT,
count INT,
message JSONB,
errorMessage JSONB,
time_creation TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
last_update TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
CREATE OR REPLACE FUNCTION update_last_update_column()
RETURNS TRIGGER AS $$
BEGIN
NEW.last_update = CURRENT_TIMESTAMP;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER update_userstat_last_update
BEFORE UPDATE ON userstat
FOR EACH ROW
EXECUTE FUNCTION update_last_update_column();