-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmysql_schema.sql
More file actions
107 lines (95 loc) · 3.68 KB
/
mysql_schema.sql
File metadata and controls
107 lines (95 loc) · 3.68 KB
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
-- Create database
CREATE DATABASE IF NOT EXISTS karl_db;
USE karl_db;
-- 1️⃣ Users Table (For SIP/WebRTC User Registrations)
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255) UNIQUE NOT NULL,
password_hash VARCHAR(255) NOT NULL,
email VARCHAR(255) UNIQUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- 2️⃣ SIP Registrations Table (For Tracking SIP Accounts)
CREATE TABLE sip_registrations (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255) NOT NULL,
domain VARCHAR(255) NOT NULL,
contact VARCHAR(255) NOT NULL,
expires TIMESTAMP NOT NULL,
registered_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
last_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
-- 3️⃣ RTP Sessions Table (For Active RTP Streams)
CREATE TABLE rtp_sessions (
id INT AUTO_INCREMENT PRIMARY KEY,
call_id VARCHAR(255) NOT NULL,
ssrc BIGINT NOT NULL,
local_ip VARCHAR(45) NOT NULL,
remote_ip VARCHAR(45) NOT NULL,
local_port INT NOT NULL,
remote_port INT NOT NULL,
started_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
last_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_call_id (call_id),
INDEX idx_remote_ip (remote_ip)
);
-- 4️⃣ Call Logs Table (For SIP/WebRTC Call History)
CREATE TABLE call_logs (
id INT AUTO_INCREMENT PRIMARY KEY,
call_id VARCHAR(255) NOT NULL,
caller VARCHAR(255) NOT NULL,
callee VARCHAR(255) NOT NULL,
start_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
end_time TIMESTAMP NULL,
status ENUM('in-progress', 'completed', 'failed') DEFAULT 'in-progress',
duration INT DEFAULT 0,
recording_url TEXT NULL,
INDEX idx_caller (caller),
INDEX idx_callee (callee),
INDEX idx_call_status (status)
);
-- 5️⃣ WebRTC Statistics Table (For Monitoring WebRTC Calls)
CREATE TABLE webrtc_stats (
id INT AUTO_INCREMENT PRIMARY KEY,
session_id VARCHAR(255) NOT NULL,
bytes_sent BIGINT DEFAULT 0,
bytes_received BIGINT DEFAULT 0,
packets_lost INT DEFAULT 0,
jitter FLOAT DEFAULT 0,
bandwidth_usage INT DEFAULT 0,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_session (session_id)
);
-- 6️⃣ RTP Transcoding Table (For Audio/Video Codec Conversions)
CREATE TABLE rtp_transcoding (
id INT AUTO_INCREMENT PRIMARY KEY,
call_id VARCHAR(255) NOT NULL,
input_codec VARCHAR(50) NOT NULL,
output_codec VARCHAR(50) NOT NULL,
transcoding_time FLOAT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
INDEX idx_transcoding_call (call_id)
);
-- 7️⃣ Redis Session Cleanup Trigger (Optional: Auto-delete Expired RTP Sessions)
DELIMITER //
CREATE TRIGGER delete_expired_sessions
AFTER INSERT ON rtp_sessions
FOR EACH ROW
BEGIN
DELETE FROM rtp_sessions WHERE last_updated < NOW() - INTERVAL 1 HOUR;
END;
//
DELIMITER ;
-- 8️⃣ Index Optimizations for Faster Queries
CREATE INDEX idx_sip_user ON sip_registrations (username);
CREATE INDEX idx_rtp_remote_ip ON rtp_sessions (remote_ip);
CREATE INDEX idx_call_status ON call_logs (status);
-- 9️⃣ Sample Data for Testing
INSERT INTO users (username, password_hash, email)
VALUES ('alice', 'hashed_password_here', 'alice@example.com');
INSERT INTO call_logs (call_id, caller, callee, status, duration)
VALUES ('abc123', 'alice', 'bob', 'completed', 120);
INSERT INTO rtp_sessions (call_id, ssrc, local_ip, remote_ip, local_port, remote_port)
VALUES ('abc123', 987654321, '192.168.1.100', '203.0.113.45', 5004, 4000);
INSERT INTO webrtc_stats (session_id, bytes_sent, bytes_received, packets_lost, jitter, bandwidth_usage)
VALUES ('session123', 1048576, 2097152, 10, 5.2, 1500);