| 
 | 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 | +CREATE INDEX IF NOT EXISTS sessions_state_idx ON sessions(state);  | 
 | 71 | +CREATE INDEX IF NOT EXISTS sessions_group_id_idx ON sessions(group_id);  | 
 | 72 | + | 
 | 73 | +-- The session_macaroon_permissions table contains the macaroon permissions  | 
 | 74 | +-- that are associated with a session.  | 
 | 75 | +CREATE TABLE IF NOT EXISTS session_macaroon_permissions (  | 
 | 76 | +    -- The auto incrementing primary key.  | 
 | 77 | +    id INTEGER PRIMARY KEY,  | 
 | 78 | + | 
 | 79 | +    -- The ID of the session in the sessions table that this permission is  | 
 | 80 | +    -- associated with.  | 
 | 81 | +    session_id BIGINT NOT NULL REFERENCES sessions(id) ON DELETE CASCADE,  | 
 | 82 | + | 
 | 83 | +    -- The entity that this permission is for.  | 
 | 84 | +    entity TEXT NOT NULL,  | 
 | 85 | + | 
 | 86 | +    -- The action that this permission is for.  | 
 | 87 | +    action TEXT NOT NULL  | 
 | 88 | +);  | 
 | 89 | +CREATE INDEX IF NOT EXISTS sessions_mac_perms_idx ON session_macaroon_permissions(session_id);  | 
 | 90 | + | 
 | 91 | +-- The session_macaroon_caveats table contains the macaroon caveats that are  | 
 | 92 | +-- associated with a session.  | 
 | 93 | +CREATE TABLE IF NOT EXISTS session_macaroon_caveats (  | 
 | 94 | +    -- The auto incrementing primary key.  | 
 | 95 | +    id INTEGER PRIMARY KEY,  | 
 | 96 | + | 
 | 97 | +    -- The ID of the session in the sessions table that this caveat is  | 
 | 98 | +    -- associated with.  | 
 | 99 | +    session_id BIGINT NOT NULL REFERENCES sessions(id) ON DELETE CASCADE,  | 
 | 100 | + | 
 | 101 | +    -- The caveat ID.  | 
 | 102 | +    caveat_id BLOB NOT NULL,  | 
 | 103 | + | 
 | 104 | +    -- The verification ID. If this is not-null, it's a third party caveat.  | 
 | 105 | +    verification_id BLOB,  | 
 | 106 | + | 
 | 107 | +    -- The location hint for third party caveats.  | 
 | 108 | +    location TEXT  | 
 | 109 | +);  | 
 | 110 | + | 
 | 111 | +CREATE INDEX IF NOT EXISTS sessions_mac_caveats_idx ON session_macaroon_caveats(session_id);  | 
 | 112 | + | 
 | 113 | +-- The session_feature_configs table contains the feature configs that are  | 
 | 114 | +-- associated with a session.  | 
 | 115 | +CREATE TABLE IF NOT EXISTS session_feature_configs (  | 
 | 116 | +    -- The ID of the session in the sessions table that this feature config is  | 
 | 117 | +    -- associated with.  | 
 | 118 | +    session_id BIGINT NOT NULL REFERENCES sessions(id) ON DELETE CASCADE,  | 
 | 119 | + | 
 | 120 | +    -- The feature name.  | 
 | 121 | +    feature_name TEXT NOT NULL,  | 
 | 122 | + | 
 | 123 | +    -- The feature config blob.  | 
 | 124 | +    config BLOB  | 
 | 125 | +);  | 
 | 126 | + | 
 | 127 | +CREATE UNIQUE INDEX session_feature_configs_unique ON session_feature_configs (  | 
 | 128 | +    session_id, feature_name  | 
 | 129 | +);  | 
 | 130 | + | 
 | 131 | +-- The session_privacy_flags table contains the privacy flags that are  | 
 | 132 | +-- associated with a session.  | 
 | 133 | +CREATE TABLE IF NOT EXISTS session_privacy_flags (  | 
 | 134 | +    -- The ID of the session in the sessions table that this privacy bit is  | 
 | 135 | +    -- associated with.  | 
 | 136 | +    session_id BIGINT NOT NULL REFERENCES sessions(id) ON DELETE CASCADE,  | 
 | 137 | + | 
 | 138 | +    -- The privacy flag bit.  | 
 | 139 | +    flag INTEGER NOT NULL  | 
 | 140 | +);  | 
 | 141 | + | 
 | 142 | +CREATE UNIQUE INDEX session_priv_flags_unique ON session_privacy_flags (  | 
 | 143 | +    session_id, flag  | 
 | 144 | +);  | 
0 commit comments