Skip to content

Commit 15db74c

Browse files
committed
db: Store browser preference in database
Signed-off-by: Zixuan James Li <[email protected]>
1 parent 41181e3 commit 15db74c

File tree

9 files changed

+797
-9
lines changed

9 files changed

+797
-9
lines changed

lib/model/database.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class Accounts extends Table {
5555
class GlobalSettings extends Table {
5656
Column<String> get themeSetting => textEnum<ThemeSetting>()
5757
.withDefault(const Variable('unset'))();
58+
59+
Column<String> get browserPreference => textEnum<BrowserPreference>()
60+
.nullable()();
5861
}
5962

6063
class UriConverter extends TypeConverter<Uri, String> {
@@ -73,6 +76,8 @@ VersionedSchema _getSchema({
7376
return Schema2(database: database);
7477
case 3:
7578
return Schema3(database: database);
79+
case 4:
80+
return Schema4(database: database);
7681
default:
7782
throw Exception('unknown schema version: $schemaVersion');
7883
}
@@ -93,7 +98,7 @@ class AppDatabase extends _$AppDatabase {
9398
// * Write a migration in `onUpgrade` below.
9499
// * Write tests.
95100
@override
96-
int get schemaVersion => 3; // See note.
101+
int get schemaVersion => 4; // See note.
97102

98103
Future<void> _dropAndCreateAll(Migrator m, {
99104
required int schemaVersion,
@@ -145,6 +150,10 @@ class AppDatabase extends _$AppDatabase {
145150
from2To3: (m, schema) async {
146151
await m.createTable(schema.globalSettings);
147152
},
153+
from3To4: (m, schema) async {
154+
await m.addColumn(
155+
schema.globalSettings, schema.globalSettings.browserPreference);
156+
},
148157
));
149158
});
150159
}

lib/model/database.g.dart

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

lib/model/schema_versions.g.dart

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,67 @@ i1.GeneratedColumn<String> _column_9(String aliasedName) =>
142142
i1.GeneratedColumn<String>('theme_setting', aliasedName, false,
143143
type: i1.DriftSqlType.string,
144144
defaultValue: const CustomExpression('\'unset\''));
145+
146+
final class Schema4 extends i0.VersionedSchema {
147+
Schema4({required super.database}) : super(version: 4);
148+
@override
149+
late final List<i1.DatabaseSchemaEntity> entities = [
150+
accounts,
151+
globalSettings,
152+
];
153+
late final Shape0 accounts = Shape0(
154+
source: i0.VersionedTable(
155+
entityName: 'accounts',
156+
withoutRowId: false,
157+
isStrict: false,
158+
tableConstraints: [
159+
'UNIQUE(realm_url, user_id)',
160+
'UNIQUE(realm_url, email)',
161+
],
162+
columns: [
163+
_column_0,
164+
_column_1,
165+
_column_2,
166+
_column_3,
167+
_column_4,
168+
_column_5,
169+
_column_6,
170+
_column_7,
171+
_column_8,
172+
],
173+
attachedDatabase: database,
174+
),
175+
alias: null);
176+
late final Shape2 globalSettings = Shape2(
177+
source: i0.VersionedTable(
178+
entityName: 'global_settings',
179+
withoutRowId: false,
180+
isStrict: false,
181+
tableConstraints: [],
182+
columns: [
183+
_column_9,
184+
_column_10,
185+
],
186+
attachedDatabase: database,
187+
),
188+
alias: null);
189+
}
190+
191+
class Shape2 extends i0.VersionedTable {
192+
Shape2({required super.source, required super.alias}) : super.aliased();
193+
i1.GeneratedColumn<String> get themeSetting =>
194+
columnsByName['theme_setting']! as i1.GeneratedColumn<String>;
195+
i1.GeneratedColumn<String> get browserPreference =>
196+
columnsByName['browser_preference']! as i1.GeneratedColumn<String>;
197+
}
198+
199+
i1.GeneratedColumn<String> _column_10(String aliasedName) =>
200+
i1.GeneratedColumn<String>('browser_preference', aliasedName, true,
201+
type: i1.DriftSqlType.string);
145202
i0.MigrationStepWithVersion migrationSteps({
146203
required Future<void> Function(i1.Migrator m, Schema2 schema) from1To2,
147204
required Future<void> Function(i1.Migrator m, Schema3 schema) from2To3,
205+
required Future<void> Function(i1.Migrator m, Schema4 schema) from3To4,
148206
}) {
149207
return (currentVersion, database) async {
150208
switch (currentVersion) {
@@ -158,6 +216,11 @@ i0.MigrationStepWithVersion migrationSteps({
158216
final migrator = i1.Migrator(database, schema);
159217
await from2To3(migrator, schema);
160218
return 3;
219+
case 3:
220+
final schema = Schema4(database: database);
221+
final migrator = i1.Migrator(database, schema);
222+
await from3To4(migrator, schema);
223+
return 4;
161224
default:
162225
throw ArgumentError.value('Unknown migration from $currentVersion');
163226
}
@@ -167,9 +230,11 @@ i0.MigrationStepWithVersion migrationSteps({
167230
i1.OnUpgrade stepByStep({
168231
required Future<void> Function(i1.Migrator m, Schema2 schema) from1To2,
169232
required Future<void> Function(i1.Migrator m, Schema3 schema) from2To3,
233+
required Future<void> Function(i1.Migrator m, Schema4 schema) from3To4,
170234
}) =>
171235
i0.VersionedSchema.stepByStepHelper(
172236
step: migrationSteps(
173237
from1To2: from1To2,
174238
from2To3: from2To3,
239+
from3To4: from3To4,
175240
));

0 commit comments

Comments
 (0)