@@ -73,6 +73,34 @@ class BoolGlobalSettings extends Table {
73
73
Set <Column <Object >>? get primaryKey => {name};
74
74
}
75
75
76
+ /// The table of the user's int-valued, account-independent settings.
77
+ ///
78
+ /// These apply across all the user's accounts on this client
79
+ /// (i.e. on this install of the app on this device).
80
+ ///
81
+ /// Each row is a [IntGlobalSettingRow] ,
82
+ /// referring to a possible setting from [IntGlobalSetting] .
83
+ /// For settings in [IntGlobalSetting] without a row in this table,
84
+ /// the setting's value is `null` .
85
+ @DataClassName ('IntGlobalSettingRow' )
86
+ class IntGlobalSettings extends Table {
87
+ /// The setting's name, a possible name from [IntGlobalSetting] .
88
+ ///
89
+ /// The table may have rows where [name] is not the name of any
90
+ /// enum value in [IntGlobalSetting] .
91
+ /// This happens if the app has previously run at a future or modified
92
+ /// version which had additional values in that enum,
93
+ /// and the user set one of those additional settings.
94
+ /// The app ignores any such unknown rows.
95
+ TextColumn get name => text ()();
96
+
97
+ /// The user's chosen value for the setting.
98
+ IntColumn get value => integer ()();
99
+
100
+ @override
101
+ Set <Column <Object >>? get primaryKey => {name};
102
+ }
103
+
76
104
/// The table of [Account] records in the app's database.
77
105
class Accounts extends Table {
78
106
/// The ID of this account in the app's local database.
@@ -116,7 +144,7 @@ class UriConverter extends TypeConverter<Uri, String> {
116
144
@override Uri fromSql (String fromDb) => Uri .parse (fromDb);
117
145
}
118
146
119
- @DriftDatabase (tables: [GlobalSettings , BoolGlobalSettings , Accounts ])
147
+ @DriftDatabase (tables: [GlobalSettings , BoolGlobalSettings , IntGlobalSettings , Accounts ])
120
148
class AppDatabase extends _$AppDatabase {
121
149
AppDatabase (super .e);
122
150
@@ -129,7 +157,7 @@ class AppDatabase extends _$AppDatabase {
129
157
// information on using the build_runner.
130
158
// * Write a migration in `_migrationSteps` below.
131
159
// * Write tests.
132
- static const int latestSchemaVersion = 9 ; // See note.
160
+ static const int latestSchemaVersion = 10 ; // See note.
133
161
134
162
@override
135
163
int get schemaVersion => latestSchemaVersion;
@@ -200,7 +228,10 @@ class AppDatabase extends _$AppDatabase {
200
228
// assume there wasn't also the legacy app before that.
201
229
await m.database.update (schema.globalSettings).write (
202
230
RawValuesInsertable ({'legacy_upgrade_state' : Constant ('noLegacy' )}));
203
- }
231
+ },
232
+ from9To10: (m, schema) async {
233
+ await m.createTable (schema.intGlobalSettings);
234
+ },
204
235
);
205
236
206
237
Future <void > _createLatestSchema (Migrator m) async {
@@ -256,6 +287,14 @@ class AppDatabase extends _$AppDatabase {
256
287
return result;
257
288
}
258
289
290
+ Future <Map <IntGlobalSetting , int >> getIntGlobalSettings () async {
291
+ return {
292
+ for (final row in await select (intGlobalSettings).get ())
293
+ if (IntGlobalSetting .byName (row.name) case final setting? )
294
+ setting: row.value
295
+ };
296
+ }
297
+
259
298
Future <int > createAccount (AccountsCompanion values) async {
260
299
try {
261
300
return await into (accounts).insert (values);
0 commit comments