Skip to content

Commit c29934a

Browse files
rajveermalviyagnprice
authored andcommitted
db: Allow storing realmName and realmIcon to the Accounts table
And update login flow to store realmName and realmIcon while creating account in the database. Fixes: #1036
1 parent 32557ca commit c29934a

File tree

13 files changed

+1620
-2
lines changed

13 files changed

+1620
-2
lines changed

lib/model/database.dart

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:drift/internal/versioned_schema.dart';
88
import 'package:drift/remote.dart';
99
import 'package:sqlite3/common.dart';
1010

11+
import '../api/route/realm.dart';
1112
import '../log.dart';
1213
import 'legacy_app_data.dart';
1314
import 'schema_versions.g.dart';
@@ -128,6 +129,20 @@ class Accounts extends Table {
128129
/// It never changes for a given account.
129130
Column<String> get realmUrl => text().map(const UriConverter())();
130131

132+
/// The name of the Zulip realm this account is on.
133+
///
134+
/// This corresponds to [GetServerSettingsResult.realmName].
135+
///
136+
/// Nullable just because older versions of the app didn't store this.
137+
Column<String> get realmName => text().nullable()();
138+
139+
/// The icon URL of the Zulip realm this account is on.
140+
///
141+
/// This corresponds to [GetServerSettingsResult.realmIcon].
142+
///
143+
/// Nullable just because older versions of the app didn't store this.
144+
Column<String> get realmIcon => text().map(const UriConverter()).nullable()();
145+
131146
/// The Zulip user ID of this account.
132147
///
133148
/// This is the identifier the server uses for the account.
@@ -169,7 +184,7 @@ class AppDatabase extends _$AppDatabase {
169184
// information on using the build_runner.
170185
// * Write a migration in `_migrationSteps` below.
171186
// * Write tests.
172-
static const int latestSchemaVersion = 11; // See note.
187+
static const int latestSchemaVersion = 12; // See note.
173188

174189
@override
175190
int get schemaVersion => latestSchemaVersion;
@@ -264,6 +279,10 @@ class AppDatabase extends _$AppDatabase {
264279
'value': Variable(firstAccountId),
265280
}));
266281
},
282+
from11To12: (Migrator m, Schema12 schema) async {
283+
await m.addColumn(schema.accounts, schema.accounts.realmName);
284+
await m.addColumn(schema.accounts, schema.accounts.realmIcon);
285+
},
267286
);
268287

269288
Future<void> _createLatestSchema(Migrator m) async {

0 commit comments

Comments
 (0)