-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb-setup.sql
More file actions
29 lines (26 loc) · 904 Bytes
/
db-setup.sql
File metadata and controls
29 lines (26 loc) · 904 Bytes
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
CREATE DATABASE IF NOT EXISTS Mailbot;
USE Mailbot;
CREATE TABLE address_whitelist (
whitelist_uid INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
whitelisted_name VARCHAR(100),
whitelisted_address VARCHAR(255) NOT NULL UNIQUE,
whitelisted_on DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE emails (
email_uid INT UNSIGNED PRIMARY KEY,
email_parent_id VARCHAR(255) NULL,
email_id VARCHAR(255) NOT NULL UNIQUE,
subject_line VARCHAR(512),
sender_name VARCHAR(255),
sender_address VARCHAR(255),
body_text MEDIUMTEXT,
sent_on DATETIME,
read_on DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (email_parent_id)
REFERENCES emails(email_id)
ON DELETE CASCADE,
FOREIGN KEY (sender_address)
REFERENCES address_whitelist(whitelisted_address)
ON DELETE CASCADE
);
CREATE INDEX email_idx ON emails(email_id, email_parent_id);