Skip to content

Commit 6bd8c76

Browse files
committed
db: Store browser preference in database
Signed-off-by: Zixuan James Li <[email protected]>
1 parent 24eba9e commit 6bd8c76

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
.nullable()();
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: 83 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
@@ -141,9 +141,67 @@ class Shape1 extends i0.VersionedTable {
141141
i1.GeneratedColumn<String> _column_9(String aliasedName) =>
142142
i1.GeneratedColumn<String>('theme_setting', aliasedName, true,
143143
type: i1.DriftSqlType.string);
144+
145+
final class Schema4 extends i0.VersionedSchema {
146+
Schema4({required super.database}) : super(version: 4);
147+
@override
148+
late final List<i1.DatabaseSchemaEntity> entities = [
149+
globalSettings,
150+
accounts,
151+
];
152+
late final Shape2 globalSettings = Shape2(
153+
source: i0.VersionedTable(
154+
entityName: 'global_settings',
155+
withoutRowId: false,
156+
isStrict: false,
157+
tableConstraints: [],
158+
columns: [
159+
_column_9,
160+
_column_10,
161+
],
162+
attachedDatabase: database,
163+
),
164+
alias: null);
165+
late final Shape0 accounts = Shape0(
166+
source: i0.VersionedTable(
167+
entityName: 'accounts',
168+
withoutRowId: false,
169+
isStrict: false,
170+
tableConstraints: [
171+
'UNIQUE(realm_url, user_id)',
172+
'UNIQUE(realm_url, email)',
173+
],
174+
columns: [
175+
_column_0,
176+
_column_1,
177+
_column_2,
178+
_column_3,
179+
_column_4,
180+
_column_5,
181+
_column_6,
182+
_column_7,
183+
_column_8,
184+
],
185+
attachedDatabase: database,
186+
),
187+
alias: null);
188+
}
189+
190+
class Shape2 extends i0.VersionedTable {
191+
Shape2({required super.source, required super.alias}) : super.aliased();
192+
i1.GeneratedColumn<String> get themeSetting =>
193+
columnsByName['theme_setting']! as i1.GeneratedColumn<String>;
194+
i1.GeneratedColumn<String> get browserPreference =>
195+
columnsByName['browser_preference']! as i1.GeneratedColumn<String>;
196+
}
197+
198+
i1.GeneratedColumn<String> _column_10(String aliasedName) =>
199+
i1.GeneratedColumn<String>('browser_preference', aliasedName, true,
200+
type: i1.DriftSqlType.string);
144201
i0.MigrationStepWithVersion migrationSteps({
145202
required Future<void> Function(i1.Migrator m, Schema2 schema) from1To2,
146203
required Future<void> Function(i1.Migrator m, Schema3 schema) from2To3,
204+
required Future<void> Function(i1.Migrator m, Schema4 schema) from3To4,
147205
}) {
148206
return (currentVersion, database) async {
149207
switch (currentVersion) {
@@ -157,6 +215,11 @@ i0.MigrationStepWithVersion migrationSteps({
157215
final migrator = i1.Migrator(database, schema);
158216
await from2To3(migrator, schema);
159217
return 3;
218+
case 3:
219+
final schema = Schema4(database: database);
220+
final migrator = i1.Migrator(database, schema);
221+
await from3To4(migrator, schema);
222+
return 4;
160223
default:
161224
throw ArgumentError.value('Unknown migration from $currentVersion');
162225
}
@@ -166,9 +229,11 @@ i0.MigrationStepWithVersion migrationSteps({
166229
i1.OnUpgrade stepByStep({
167230
required Future<void> Function(i1.Migrator m, Schema2 schema) from1To2,
168231
required Future<void> Function(i1.Migrator m, Schema3 schema) from2To3,
232+
required Future<void> Function(i1.Migrator m, Schema4 schema) from3To4,
169233
}) =>
170234
i0.VersionedSchema.stepByStepHelper(
171235
step: migrationSteps(
172236
from1To2: from1To2,
173237
from2To3: from2To3,
238+
from3To4: from3To4,
174239
));

0 commit comments

Comments
 (0)