@@ -119,7 +119,13 @@ static void open(final SQLiteConnection conn, final boolean readOnly) throws SQL
119119 conn .exec ("PRAGMA journal_mode = WAL" );
120120 }
121121
122- private static void createAccountsTable (final SQLiteConnection conn ) throws SQLiteException {
122+ private static void createAttestationTablesAndIndices (final SQLiteConnection conn ) throws SQLiteException {
123+ conn .exec (
124+ "CREATE TABLE IF NOT EXISTS Configuration (\n " +
125+ "key TEXT PRIMARY KEY NOT NULL,\n " +
126+ "value NOT NULL\n " +
127+ ")" );
128+
123129 conn .exec (
124130 "CREATE TABLE IF NOT EXISTS Accounts (\n " +
125131 "userId INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n " +
@@ -132,14 +138,29 @@ private static void createAccountsTable(final SQLiteConnection conn) throws SQLi
132138 "verifyInterval INTEGER NOT NULL,\n " +
133139 "alertDelay INTEGER NOT NULL\n " +
134140 ")" );
135- }
136-
137- private static void createAccountsIndices (final SQLiteConnection conn ) throws SQLiteException {
138141 conn .exec ("CREATE INDEX IF NOT EXISTS Accounts_loginTime " +
139142 "ON Accounts (loginTime)" );
140- }
141143
142- private static void createDevicesTable (final SQLiteConnection conn ) throws SQLiteException {
144+ conn .exec (
145+ "CREATE TABLE IF NOT EXISTS EmailAddresses (\n " +
146+ "userId INTEGER NOT NULL REFERENCES Accounts (userId) ON DELETE CASCADE,\n " +
147+ "address TEXT NOT NULL,\n " +
148+ "PRIMARY KEY (userId, address)\n " +
149+ ")" );
150+
151+ conn .exec (
152+ "CREATE TABLE IF NOT EXISTS Sessions (\n " +
153+ "sessionId INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n " +
154+ "userId INTEGER NOT NULL REFERENCES Accounts (userId) ON DELETE CASCADE,\n " +
155+ "cookieToken BLOB NOT NULL,\n " +
156+ "requestToken BLOB NOT NULL,\n " +
157+ "expiryTime INTEGER NOT NULL\n " +
158+ ")" );
159+ conn .exec ("CREATE INDEX IF NOT EXISTS Sessions_expiryTime " +
160+ "ON Sessions (expiryTime)" );
161+ conn .exec ("CREATE INDEX IF NOT EXISTS Sessions_userId " +
162+ "ON Sessions (userId)" );
163+
143164 conn .exec (
144165 "CREATE TABLE IF NOT EXISTS Devices (\n " +
145166 "fingerprint BLOB NOT NULL PRIMARY KEY,\n " +
@@ -171,9 +192,6 @@ private static void createDevicesTable(final SQLiteConnection conn) throws SQLit
171192 "userId INTEGER NOT NULL REFERENCES Accounts (userId) ON DELETE CASCADE,\n " +
172193 "deletionTime INTEGER\n " +
173194 ")" );
174- }
175-
176- private static void createDevicesIndices (final SQLiteConnection conn ) throws SQLiteException {
177195 conn .exec ("CREATE INDEX IF NOT EXISTS Devices_userId_verifiedTimeFirst " +
178196 "ON Devices (userId, verifiedTimeFirst)" );
179197 conn .exec ("CREATE INDEX IF NOT EXISTS Devices_userId_verifiedTimeLast_deletionTimeNull " +
@@ -182,9 +200,7 @@ private static void createDevicesIndices(final SQLiteConnection conn) throws SQL
182200 "ON Devices (deletionTime) WHERE deletionTime IS NOT NULL" );
183201 conn .exec ("CREATE INDEX IF NOT EXISTS Devices_verifiedTimeLast_deletionTimeNull " +
184202 "ON Devices (verifiedTimeLast) WHERE deletionTime IS NULL" );
185- }
186203
187- private static void createAttestationsTable (final SQLiteConnection conn ) throws SQLiteException {
188204 conn .exec (
189205 "CREATE TABLE IF NOT EXISTS Attestations (\n " +
190206 "id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n " +
@@ -194,9 +210,6 @@ private static void createAttestationsTable(final SQLiteConnection conn) throws
194210 "teeEnforced TEXT NOT NULL,\n " +
195211 "osEnforced TEXT NOT NULL\n " +
196212 ")" );
197- }
198-
199- private static void createAttestationsIndices (final SQLiteConnection conn ) throws SQLiteException {
200213 conn .exec ("CREATE INDEX IF NOT EXISTS Attestations_fingerprint_id " +
201214 "ON Attestations (fingerprint, id)" );
202215 }
@@ -230,35 +243,7 @@ public static void main(final String[] args) throws Exception {
230243 getUserVersion .dispose ();
231244 logger .info ("Existing schema version: " + userVersion );
232245
233- attestationConn .exec (
234- "CREATE TABLE IF NOT EXISTS Configuration (\n " +
235- "key TEXT PRIMARY KEY NOT NULL,\n " +
236- "value NOT NULL\n " +
237- ")" );
238- createAccountsTable (attestationConn );
239- createAccountsIndices (attestationConn );
240- attestationConn .exec (
241- "CREATE TABLE IF NOT EXISTS EmailAddresses (\n " +
242- "userId INTEGER NOT NULL REFERENCES Accounts (userId) ON DELETE CASCADE,\n " +
243- "address TEXT NOT NULL,\n " +
244- "PRIMARY KEY (userId, address)\n " +
245- ")" );
246- attestationConn .exec (
247- "CREATE TABLE IF NOT EXISTS Sessions (\n " +
248- "sessionId INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n " +
249- "userId INTEGER NOT NULL REFERENCES Accounts (userId) ON DELETE CASCADE,\n " +
250- "cookieToken BLOB NOT NULL,\n " +
251- "requestToken BLOB NOT NULL,\n " +
252- "expiryTime INTEGER NOT NULL\n " +
253- ")" );
254- attestationConn .exec ("CREATE INDEX IF NOT EXISTS Sessions_expiryTime " +
255- "ON Sessions (expiryTime)" );
256- attestationConn .exec ("CREATE INDEX IF NOT EXISTS Sessions_userId " +
257- "ON Sessions (userId)" );
258- createDevicesTable (attestationConn );
259- createDevicesIndices (attestationConn );
260- createAttestationsTable (attestationConn );
261- createAttestationsIndices (attestationConn );
246+ createAttestationTablesAndIndices (attestationConn );
262247
263248 attestationConn .exec ("INSERT OR IGNORE INTO Configuration " +
264249 "(key, value) VALUES ('backups', 0)" );
0 commit comments