Skip to content

Commit 222746c

Browse files
refactor(storage): remove unneeded idempotency guard in 14→15
1 parent 87cdfe6 commit 222746c

2 files changed

Lines changed: 7 additions & 68 deletions

File tree

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:bb_mobile/core/storage/sqlite_database.steps.dart';
2-
import 'package:bb_mobile/core/utils/logger.dart';
32
import 'package:drift/drift.dart';
43

54
/// Migration from version 14 to 15.
@@ -13,41 +12,14 @@ import 'package:drift/drift.dart';
1312
/// the user opts out).
1413
class Schema14To15 {
1514
static Future<void> migrate(Migrator m, Schema15 schema15) async {
16-
await _addColumnIfNotExists(
17-
() => m.addColumn(schema15.settings, schema15.settings.torTransportMode),
18-
'settings.tor_transport_mode column',
15+
await m.addColumn(schema15.settings, schema15.settings.torTransportMode);
16+
await m.addColumn(
17+
schema15.settings,
18+
schema15.settings.lastSuccessfulTorTransport,
1919
);
20-
await _addColumnIfNotExists(
21-
() => m.addColumn(
22-
schema15.settings,
23-
schema15.settings.lastSuccessfulTorTransport,
24-
),
25-
'settings.last_successful_tor_transport column',
26-
);
27-
await _addColumnIfNotExists(
28-
() => m.addColumn(
29-
schema15.settings,
30-
schema15.settings.screenCaptureProtectionEnabled,
31-
),
32-
'settings.screen_capture_protection_enabled column',
33-
);
34-
}
35-
}
36-
37-
Future<void> _addColumnIfNotExists(
38-
Future<void> Function() addColumn,
39-
String description,
40-
) async {
41-
try {
42-
await addColumn();
43-
} catch (e) {
44-
// Idempotency guard: only swallow "duplicate column" (a re-run over a
45-
// partially-applied migration) — log it so a driver wording change surfaces
46-
// instead of silently becoming a hard failure.
47-
if (!e.toString().contains('duplicate column')) rethrow;
48-
log.warning(
49-
'Schema14To15: $description already exists — skipping add',
50-
error: e,
20+
await m.addColumn(
21+
schema15.settings,
22+
schema15.settings.screenCaptureProtectionEnabled,
5123
);
5224
}
5325
}

test/migrations_test/bull_database/schema_v14_to_v15_test.dart

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -46,37 +46,4 @@ void main() {
4646
expect(settings.single.screenCaptureProtectionEnabled, 1);
4747
await migratedDb.close();
4848
});
49-
50-
test(
51-
'v14 to v15 tolerates tor columns already present (idempotency guard)',
52-
() async {
53-
final schema = await verifier.schemaAt(14);
54-
55-
// Simulate a dev device that received the tor columns from develop's
56-
// earlier, broken 13->14 build: add them onto the released v14 settings
57-
// table before upgrading.
58-
final seeded = v14.DatabaseAtV14(schema.newConnection());
59-
await seeded.customStatement(
60-
"ALTER TABLE settings ADD COLUMN tor_transport_mode TEXT NOT NULL "
61-
"DEFAULT 'automatic'",
62-
);
63-
await seeded.customStatement(
64-
'ALTER TABLE settings ADD COLUMN last_successful_tor_transport TEXT',
65-
);
66-
await seeded.close();
67-
68-
// Opening the app database runs the 14->15 migration. The _addColumnIfNot
69-
// Exists guard must skip the duplicate tor adds instead of throwing, and
70-
// still add the new screen-capture column.
71-
final db = SqliteDatabase(schema.newConnection());
72-
final columns = await db
73-
.customSelect("SELECT name FROM pragma_table_info('settings')")
74-
.map((row) => row.read<String>('name'))
75-
.get();
76-
expect(columns, contains('tor_transport_mode'));
77-
expect(columns, contains('last_successful_tor_transport'));
78-
expect(columns, contains('screen_capture_protection_enabled'));
79-
await db.close();
80-
},
81-
);
8249
}

0 commit comments

Comments
 (0)