CREATE TABLE message_segments (
    hash BLOB NOT NULL,
    segment_index INTEGER NOT NULL,
    segments_count INTEGER NOT NULL,
    payload BLOB NOT NULL,
    sig_pub_key BLOB NOT NULL,
    timestamp INTEGER NOT NULL,
    parity_segment_index INTEGER NOT NULL,
    parity_segments_count INTEGER NOT NULL,
    PRIMARY KEY (hash, sig_pub_key, segment_index, segments_count, parity_segment_index, parity_segments_count) ON CONFLICT REPLACE
);

CREATE TABLE IF NOT EXISTS message_segments_completed (
    hash BLOB NOT NULL,
    sig_pub_key BLOB NOT NULL,
    timestamp INTEGER DEFAULT 0,
    PRIMARY KEY (hash, sig_pub_key)
);

CREATE INDEX idx_message_segments_timestamp ON message_segments(timestamp);
CREATE INDEX idx_message_segments_completed_timestamp ON message_segments_completed(timestamp);
