@@ -110,13 +110,23 @@ class Accounts extends Table {
110
110
];
111
111
}
112
112
113
+ /// The table of one [NavigationData] record, the user's last visited account.
114
+ ///
115
+ /// These apply across all the user's accounts on this client (i.e. on this
116
+ /// install of the app on this device).
117
+ ///
118
+ /// This table can have at most one row.
119
+ class Navigation extends Table {
120
+ IntColumn get accountId => integer ().nullable ()();
121
+ }
122
+
113
123
class UriConverter extends TypeConverter <Uri , String > {
114
124
const UriConverter ();
115
125
@override String toSql (Uri value) => value.toString ();
116
126
@override Uri fromSql (String fromDb) => Uri .parse (fromDb);
117
127
}
118
128
119
- @DriftDatabase (tables: [GlobalSettings , BoolGlobalSettings , Accounts ])
129
+ @DriftDatabase (tables: [GlobalSettings , BoolGlobalSettings , Accounts , Navigation ])
120
130
class AppDatabase extends _$AppDatabase {
121
131
AppDatabase (super .e);
122
132
@@ -129,7 +139,7 @@ class AppDatabase extends _$AppDatabase {
129
139
// information on using the build_runner.
130
140
// * Write a migration in `_migrationSteps` below.
131
141
// * Write tests.
132
- static const int latestSchemaVersion = 9 ; // See note.
142
+ static const int latestSchemaVersion = 10 ; // See note.
133
143
134
144
@override
135
145
int get schemaVersion => latestSchemaVersion;
@@ -200,7 +210,10 @@ class AppDatabase extends _$AppDatabase {
200
210
// assume there wasn't also the legacy app before that.
201
211
await m.database.update (schema.globalSettings).write (
202
212
RawValuesInsertable ({'legacy_upgrade_state' : Constant ('noLegacy' )}));
203
- }
213
+ },
214
+ from9To10: (m, schema) async {
215
+ await m.createTable (schema.navigation);
216
+ },
204
217
);
205
218
206
219
Future <void > _createLatestSchema (Migrator m) async {
@@ -271,6 +284,10 @@ class AppDatabase extends _$AppDatabase {
271
284
rethrow ;
272
285
}
273
286
}
287
+
288
+ Future <NavigationData ?> getNavigation () async {
289
+ return await (select (navigation)..limit (1 )).getSingleOrNull ();
290
+ }
274
291
}
275
292
276
293
class AccountAlreadyExistsException implements Exception {}
0 commit comments