-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase_schema.sql
More file actions
71 lines (66 loc) · 2.76 KB
/
database_schema.sql
File metadata and controls
71 lines (66 loc) · 2.76 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
-- Resume Sender Database Schema
-- Database: resumesender
-- Drop existing tables if they exist
DROP TABLE IF EXISTS email_attachments;
DROP TABLE IF EXISTS email_logs;
DROP TABLE IF EXISTS recipients;
DROP TABLE IF EXISTS smtp_configurations;
-- SMTP Configurations Table
CREATE TABLE smtp_configurations (
id INT AUTO_INCREMENT PRIMARY KEY,
server_name VARCHAR(255) NOT NULL,
provider VARCHAR(50) DEFAULT 'custom',
smtp_host VARCHAR(255) NOT NULL,
smtp_port INT NOT NULL DEFAULT 587,
smtp_username VARCHAR(255) NOT NULL,
smtp_password VARCHAR(255) NOT NULL,
smtp_encryption ENUM('none', 'tls', 'ssl') DEFAULT 'tls',
from_email VARCHAR(255) NOT NULL,
from_name VARCHAR(255) NOT NULL,
daily_quota INT DEFAULT 500,
quota_exceeded_at DATETIME NULL DEFAULT NULL,
is_active TINYINT(1) DEFAULT 1,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_active (is_active)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Recipients Table
CREATE TABLE recipients (
id INT AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(255) NOT NULL,
company_name VARCHAR(255) NOT NULL,
position VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
UNIQUE KEY unique_email (email),
INDEX idx_email (email),
INDEX idx_company (company_name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Email Logs Table
CREATE TABLE email_logs (
id INT AUTO_INCREMENT PRIMARY KEY,
recipient_id INT NOT NULL,
smtp_config_id INT NOT NULL,
subject VARCHAR(500) NOT NULL,
body TEXT NOT NULL,
sent_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
status ENUM('success', 'failed') DEFAULT 'success',
error_message TEXT,
FOREIGN KEY (recipient_id) REFERENCES recipients(id) ON DELETE CASCADE,
FOREIGN KEY (smtp_config_id) REFERENCES smtp_configurations(id) ON DELETE CASCADE,
INDEX idx_recipient (recipient_id),
INDEX idx_smtp (smtp_config_id),
INDEX idx_sent_at (sent_at),
INDEX idx_status (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Email Attachments Table
CREATE TABLE email_attachments (
id INT AUTO_INCREMENT PRIMARY KEY,
email_log_id INT NOT NULL,
file_name VARCHAR(255) NOT NULL,
file_path VARCHAR(500) NOT NULL,
file_size INT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (email_log_id) REFERENCES email_logs(id) ON DELETE CASCADE,
INDEX idx_email_log (email_log_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;