-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from xmtp/07-31-create-db-schema
Create initial DB schema
- Loading branch information
Showing
4 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
DROP TABLE node_info; | ||
DROP TABLE all_envelopes; | ||
DROP TABLE staged_originated_envelopes; | ||
DROP TABLE address_log; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,50 @@ | ||
SELECT | ||
1; | ||
-- Ensures that if the command-line node configuration mutates, | ||
-- the existing data in the DB is invalid | ||
CREATE TABLE node_info( | ||
node_id INTEGER NOT NULL, | ||
public_key BYTEA NOT NULL, | ||
|
||
singleton_id SMALLINT PRIMARY KEY DEFAULT 1, | ||
CONSTRAINT is_singleton CHECK (singleton_id = 1) | ||
); | ||
|
||
CREATE TABLE all_envelopes( | ||
-- used to construct gateway_sid | ||
id BIGSERIAL PRIMARY KEY, | ||
originator_sid BIGINT NOT NULL, | ||
topic BYTEA NOT NULL, | ||
originator_envelope BYTEA NOT NULL | ||
); | ||
-- Client queries | ||
CREATE INDEX idx_all_envelopes_topic ON all_envelopes(topic); | ||
-- Node queries | ||
CREATE UNIQUE INDEX idx_all_envelopes_originator_sid ON all_envelopes(originator_sid); | ||
|
||
|
||
-- Process for originating envelopes: | ||
-- 1. Perform any necessary validation | ||
-- 2. Insert into originated_envelopes | ||
-- 3. Singleton background task will continuously query (or subscribe to) | ||
-- staged_originated_envelopes, and for each envelope in order of ID: | ||
-- 2.1. Construct and sign OriginatorEnvelope proto | ||
-- 2.2. Atomically insert into all_envelopes and delete from originated_envelopes, | ||
-- ignoring unique index violations on originator_sid | ||
-- This preserves total ordering, while avoiding gaps in sequence ID's. | ||
CREATE TABLE staged_originated_envelopes( | ||
-- used to construct originator_sid | ||
id BIGSERIAL PRIMARY KEY, | ||
originator_ns TIMESTAMP NOT NULL DEFAULT now(), | ||
payer_envelope BYTEA NOT NULL | ||
); | ||
|
||
-- A cached view for looking up the inbox_id that an address belongs to. | ||
-- Relies on a total ordering of updates across all inbox_ids, from which this | ||
-- view can be deterministically generated. | ||
CREATE TABLE address_log( | ||
address TEXT NOT NULL, | ||
inbox_id BYTEA NOT NULL, | ||
association_sequence_id BIGINT, | ||
revocation_sequence_id BIGINT, | ||
|
||
PRIMARY KEY (address, inbox_id) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters