Skip to content

Commit 294d842

Browse files
committed
db: Store Navigation (last visited account id) in database
1 parent 7e98ff1 commit 294d842

File tree

6 files changed

+1569
-4
lines changed

6 files changed

+1569
-4
lines changed

lib/model/database.dart

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,23 @@ class Accounts extends Table {
110110
];
111111
}
112112

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+
113123
class UriConverter extends TypeConverter<Uri, String> {
114124
const UriConverter();
115125
@override String toSql(Uri value) => value.toString();
116126
@override Uri fromSql(String fromDb) => Uri.parse(fromDb);
117127
}
118128

119-
@DriftDatabase(tables: [GlobalSettings, BoolGlobalSettings, Accounts])
129+
@DriftDatabase(tables: [GlobalSettings, BoolGlobalSettings, Accounts, Navigation])
120130
class AppDatabase extends _$AppDatabase {
121131
AppDatabase(super.e);
122132

@@ -129,7 +139,7 @@ class AppDatabase extends _$AppDatabase {
129139
// information on using the build_runner.
130140
// * Write a migration in `_migrationSteps` below.
131141
// * Write tests.
132-
static const int latestSchemaVersion = 9; // See note.
142+
static const int latestSchemaVersion = 10; // See note.
133143

134144
@override
135145
int get schemaVersion => latestSchemaVersion;
@@ -200,7 +210,10 @@ class AppDatabase extends _$AppDatabase {
200210
// assume there wasn't also the legacy app before that.
201211
await m.database.update(schema.globalSettings).write(
202212
RawValuesInsertable({'legacy_upgrade_state': Constant('noLegacy')}));
203-
}
213+
},
214+
from9To10: (m, schema) async {
215+
await m.createTable(schema.navigation);
216+
},
204217
);
205218

206219
Future<void> _createLatestSchema(Migrator m) async {
@@ -271,6 +284,10 @@ class AppDatabase extends _$AppDatabase {
271284
rethrow;
272285
}
273286
}
287+
288+
Future<NavigationData?> getNavigation() async {
289+
return await (select(navigation)..limit(1)).getSingleOrNull();
290+
}
274291
}
275292

276293
class AccountAlreadyExistsException implements Exception {}

lib/model/database.g.dart

Lines changed: 289 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)