Needed to rethink storage strategies as I researched this and realized that a true scarce database -- where the database is sparsely populated both in columns and rows -- is not feasible due to IMAP's UID rules. The strategy now means that the database rows are contiguous from the highest (newest) message to the oldest *requested by the user*. This is a better situation than having to download the UID for the entire folder.
93 lines
1.9 KiB
SQL
93 lines
1.9 KiB
SQL
|
|
--
|
|
-- FolderTable
|
|
--
|
|
|
|
CREATE TABLE FolderTable (
|
|
id INTEGER PRIMARY KEY,
|
|
name TEXT NOT NULL,
|
|
parent_id INTEGER REFERENCES FolderTable ON DELETE RESTRICT
|
|
);
|
|
|
|
CREATE INDEX FolderTableNameIndex ON FolderTable(name);
|
|
CREATE INDEX FolderTableParentIndex ON FolderTable(parent_id);
|
|
|
|
--
|
|
-- MessageTable
|
|
--
|
|
|
|
CREATE TABLE MessageTable (
|
|
id INTEGER PRIMARY KEY,
|
|
fields INTEGER,
|
|
|
|
date_field TEXT,
|
|
date_time_t INTEGER,
|
|
|
|
from_field TEXT,
|
|
sender TEXT,
|
|
reply_to TEXT,
|
|
|
|
to_field TEXT,
|
|
cc TEXT,
|
|
bcc TEXT,
|
|
|
|
message_id TEXT,
|
|
in_reply_to TEXT,
|
|
|
|
subject TEXT,
|
|
|
|
header TEXT,
|
|
|
|
body TEXT
|
|
);
|
|
|
|
CREATE INDEX MessageTableMessageIDIndex ON MessageTable(message_id);
|
|
|
|
--
|
|
-- MessageLocationTable
|
|
--
|
|
|
|
CREATE TABLE MessageLocationTable (
|
|
id INTEGER PRIMARY KEY,
|
|
message_id INTEGER REFERENCES MessageTable ON DELETE CASCADE,
|
|
folder_id INTEGER REFERENCES FolderTable ON DELETE CASCADE,
|
|
ordering INTEGER
|
|
);
|
|
|
|
CREATE INDEX MessageLocationTableMessageIDIndex ON MessageLocationTable(message_id);
|
|
CREATE INDEX MessageLocationTableFolderIDIndex ON MessageLocationTable(folder_id);
|
|
CREATE INDEX MessageLocationTableOrderingIndex ON MessageLocationTable(ordering ASC);
|
|
|
|
--
|
|
-- IMAP-specific tables
|
|
--
|
|
|
|
--
|
|
-- ImapFolderPropertiesTable
|
|
--
|
|
|
|
CREATE TABLE ImapFolderPropertiesTable (
|
|
id INTEGER PRIMARY KEY,
|
|
folder_id INTEGER UNIQUE REFERENCES FolderTable ON DELETE CASCADE,
|
|
last_seen_total INTEGER,
|
|
uid_validity INTEGER,
|
|
uid_next INTEGER,
|
|
attributes TEXT
|
|
);
|
|
|
|
CREATE INDEX ImapFolderPropertiesTableFolderIDIndex ON ImapFolderPropertiesTable(folder_id);
|
|
|
|
--
|
|
-- ImapMessagePropertiesTable
|
|
--
|
|
|
|
CREATE TABLE ImapMessagePropertiesTable (
|
|
id INTEGER PRIMARY KEY,
|
|
message_id INTEGER UNIQUE REFERENCES MessageTable ON DELETE CASCADE,
|
|
flags TEXT,
|
|
internaldate TEXT,
|
|
rfc822_size INTEGER
|
|
);
|
|
|
|
CREATE INDEX ImapMessagePropertiesTableMessageIDIndex ON ImapMessagePropertiesTable(message_id);
|
|
|