-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.sql
88 lines (78 loc) · 2.17 KB
/
db.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
CREATE TABLE user (
user_id INTEGER PRIMARY KEY,
username TEXT,
f_name TEXT,
l_name TEXT,
password TEXT,
msisdn TEXT,
PIN TEXT
);
CREATE TABLE contact (
contact_id INTEGER PRIMARY KEY,
user_id INTEGER NOT NULL,
f_name TEXT,
l_name TEXT,
full_name TEXT NOT NULL,
g_id TEXT NOT NULL,
FOREIGN KEY(user_id) REFERENCES user(user_id)
);
CREATE TABLE contact_phone_number (
contact_id INTEGER NOT NULL,
type TEXT NOT NULL,
number TEXT NOT NULL,
FOREIGN KEY(contact_id) REFERENCES contact(contact_id)
);
CREATE TABLE call (
call_id INTEGER PRIMARY KEY,
call_from TEXT NOT NULL,
call_to TEXT NOT NULL,
duration INTEGER DEFAULT NULL,
status TEXT DEFAULT NULL,
direction INTEGER NOT NULL,
ts timestamp,
parent_call_id INTEGER,
FOREIGN KEY(parent_call_id) REFERENCES call(call_id)
);
CREATE TABLE twilio_call (
call_sid TEXT PRIMARY KEY,
account_sid TEXT NOT NULL,
call_id INTEGER NOT NULL,
FOREIGN KEY(call_id) REFERENCES call(call_id)
);
CREATE TABLE asterisk_call (
call_uid TEXT PRIMARY KEY,
context TEXT TEXt NOT NULL,
call_id INTEGER NOT NULL,
FOREIGN KEY(call_id) REFERENCES call(call_id)
);
CREATE TABLE user_auth_attempt (
msisdn TEXT NOT NULL,
call_id INTEGER NOT NULL,
ts timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
auth_code INTEGER NOT NULL,
user_id INTEGER,
FOREIGN KEY(call_id) REFERENCES call(call_id),
FOREIGN KEY(user_id) REFERENCES user(user_id)
);
CREATE TABLE authenticated_call (
user_id INTEGER NOT NULL,
call_id INTEGER NOT NULL,
FOREIGN KEY(user_id) REFERENCES user(user_id),
FOREIGN KEY(call_id) REFERENCES call(call_id)
);
CREATE TABLE call_auth_msisdn (
call_id INTEGER NOT NULL,
msisdn TEXT NOT NULL,
FOREIGN KEY(call_id) REFERENCES call(call_id)
);
CREATE TABLE user_auth_blacklist (
msisdn TEXT NOT NULL,
expiry timestamp NOT NULL
);
CREATE TABLE call_matched_contact (
call_id INTEGER NOT NULL,
contact_id INTEGER NOT NULL,
selected INTEGER NULL,
FOREIGN KEY(call_id) REFERENCES call(call_id),
FOREIGN KEY(contact_id) REFERENCES contact(contact_id)
);