1+ -- The sessions table contains LNC session related information.
2+ CREATE TABLE IF NOT EXISTS sessions (
3+ -- The auto incrementing primary key.
4+ id INTEGER PRIMARY KEY ,
5+
6+ -- The ID that was used to identify the session in the legacy KVDB store.
7+ -- This is derived directly from the local_public_key. In order to avoid
8+ -- breaking the API, we keep this field here so that we can still look up
9+ -- sessions by this ID.
10+ alias BLOB NOT NULL UNIQUE,
11+
12+ -- The session's given label.
13+ label TEXT NOT NULL ,
14+
15+ -- The session's current state.
16+ state SMALLINT NOT NULL ,
17+
18+ -- The session type.
19+ type SMALLINT NOT NULL ,
20+
21+ -- expiry is the time that the session will expire.
22+ expiry TIMESTAMP NOT NULL ,
23+
24+ -- The session's creation time.
25+ created_at TIMESTAMP NOT NULL ,
26+
27+ -- The time at which the session was revoked.
28+ revoked_at TIMESTAMP ,
29+
30+ -- The mailbox server address.
31+ server_address TEXT NOT NULL ,
32+
33+ -- Whether the connection to the server should not use TLS.
34+ dev_server BOOLEAN NOT NULL ,
35+
36+ -- The root key ID to use when baking a macaroon for this session.
37+ macaroon_root_key BIGINT NOT NULL ,
38+
39+ -- The passphrase entropy to use when deriving the mnemonic for this LNC
40+ -- session.
41+ pairing_secret BLOB NOT NULL ,
42+
43+ -- The private key of the long term local static key for this LNC session.
44+ local_private_key BLOB NOT NULL ,
45+
46+ -- The public key of the long term local static key for this LNC session.
47+ -- This is derivable from the local_private_key but is stored here since
48+ -- the local public key was used to identify a session when the DB was KVDB
49+ -- based and so to keep the API consistent, we store it here so that we can
50+ -- still look up sessions by this public key.
51+ local_public_key BLOB NOT NULL UNIQUE,
52+
53+ -- The public key of the long term remote static key for this LNC session.
54+ remote_public_key BLOB,
55+
56+ -- Whether the privacy mapper should be used for this session.
57+ privacy BOOLEAN NOT NULL ,
58+
59+ -- An optional account ID that this session is linked to.
60+ account_id BIGINT REFERENCES accounts(id) ON DELETE CASCADE ,
61+
62+ -- The session ID of the first session in this linked session group. This
63+ -- is nullable for the case where the first session in the group is being
64+ -- inserted, and so we first need to insert the session before we know the
65+ -- ID to use for the group ID.
66+ group_id BIGINT REFERENCES sessions(id) ON DELETE CASCADE
67+ );
68+
69+ CREATE INDEX IF NOT EXISTS sessions_type_idx ON sessions(type);
70+
71+ -- The session_macaroon_permissions table contains the macaroon permissions
72+ -- that are associated with a session.
73+ CREATE TABLE IF NOT EXISTS session_macaroon_permissions (
74+ -- The ID of the session in the sessions table that this permission is
75+ -- associated with.
76+ session_id BIGINT NOT NULL REFERENCES sessions(id) ON DELETE CASCADE ,
77+
78+ -- The entity that this permission is for.
79+ entity TEXT NOT NULL ,
80+
81+ -- The action that this permission is for.
82+ action TEXT NOT NULL
83+ );
84+
85+ -- The session_macaroon_caveats table contains the macaroon caveats that are
86+ -- associated with a session.
87+ CREATE TABLE IF NOT EXISTS session_macaroon_caveats (
88+ -- The ID of the session in the sessions table that this caveat is
89+ -- associated with.
90+ session_id BIGINT NOT NULL REFERENCES sessions(id) ON DELETE CASCADE ,
91+
92+ -- The caveat ID.
93+ id BLOB NOT NULL ,
94+
95+ -- The verification ID. If this is not-null, it's a third party caveat.
96+ verification_id BLOB,
97+
98+ -- The location hint for third party caveats.
99+ location TEXT
100+ );
101+
102+ -- The session_feature_configs table contains the feature configs that are
103+ -- associated with a session.
104+ CREATE TABLE IF NOT EXISTS session_feature_configs (
105+ -- The ID of the session in the sessions table that this feature config is
106+ -- associated with.
107+ session_id BIGINT NOT NULL REFERENCES sessions(id) ON DELETE CASCADE ,
108+
109+ -- The feature name.
110+ feature_name TEXT NOT NULL ,
111+
112+ -- The feature config blob.
113+ config BLOB
114+ );
115+
116+ -- The session_privacy_flags table contains the privacy flags that are
117+ -- associated with a session.
118+ CREATE TABLE IF NOT EXISTS session_privacy_flags (
119+ -- The ID of the session in the sessions table that this privacy bit is
120+ -- associated with.
121+ session_id BIGINT NOT NULL REFERENCES sessions(id) ON DELETE CASCADE ,
122+
123+ -- The privacy flag bit.
124+ flag INTEGER NOT NULL ,
125+
126+ -- The flag bit is unique per session.
127+ UNIQUE (flag, session_id)
128+ );
0 commit comments