Skip to content

Commit 0b85d53

Browse files
fix: inline inserts in schema instead of using db seeds
1 parent ad83c40 commit 0b85d53

2 files changed

Lines changed: 63 additions & 8 deletions

File tree

lib/core/storage/database_seeds.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ class DatabaseSeeds {
118118

119119
static Future<void> seedDefaultMempoolServers(SqliteDatabase db) async {
120120
final serversData = [
121-
('mempool.bullbitcoin.com', false, false),
122-
('mempool.space/testnet', true, false),
123-
('liquid.bullbitcoin.com', false, true),
124-
('liquid.bullbitcoin.com/testnet', true, true),
121+
(ApiServiceConstants.bbMempoolUrlPath, false, false),
122+
(ApiServiceConstants.testnetMempoolUrlPath, true, false),
123+
(ApiServiceConstants.bbLiquidMempoolUrlPath, false, true),
124+
(ApiServiceConstants.bbLiquidMempoolTestnetUrlPath, true, true),
125125
];
126126

127127
for (final (url, isTestnet, isLiquid) in serversData) {

lib/core/storage/migrations/schema_10_to_11.dart

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:bb_mobile/core/storage/database_seeds.dart';
21
import 'package:bb_mobile/core/storage/sqlite_database.dart';
32
import 'package:bb_mobile/core/storage/sqlite_database.steps.dart';
43
import 'package:bb_mobile/core/utils/constants.dart';
@@ -99,8 +98,64 @@ class Schema10To11 {
9998
await m.createTable(schema11.mempoolServers);
10099
await m.createTable(schema11.mempoolSettings);
101100

102-
// Seed default mempool data
103-
await DatabaseSeeds.seedDefaultMempoolServers(db);
104-
await DatabaseSeeds.seedDefaultMempoolSettings(db);
101+
// Seed default mempool servers
102+
final mempoolServers = schema11.mempoolServers;
103+
final mempoolServersData = [
104+
{
105+
'url': ApiServiceConstants.bbMempoolUrlPath,
106+
'isTestnet': false,
107+
'isLiquid': false,
108+
'isCustom': false,
109+
},
110+
{
111+
'url': ApiServiceConstants.testnetMempoolUrlPath,
112+
'isTestnet': true,
113+
'isLiquid': false,
114+
'isCustom': false,
115+
},
116+
{
117+
'url': ApiServiceConstants.bbLiquidMempoolUrlPath,
118+
'isTestnet': false,
119+
'isLiquid': true,
120+
'isCustom': false,
121+
},
122+
{
123+
'url': ApiServiceConstants.bbLiquidMempoolTestnetUrlPath,
124+
'isTestnet': true,
125+
'isLiquid': true,
126+
'isCustom': false,
127+
},
128+
];
129+
for (final server in mempoolServersData) {
130+
await db
131+
.into(mempoolServers)
132+
.insertOnConflictUpdate(
133+
RawValuesInsertable({
134+
'url': Constant(server['url']),
135+
'is_testnet': Constant(server['isTestnet']),
136+
'is_liquid': Constant(server['isLiquid']),
137+
'is_custom': Constant(server['isCustom']),
138+
}),
139+
);
140+
}
141+
142+
// Seed default mempool settings
143+
final mempoolSettings = schema11.mempoolSettings;
144+
final mempoolNetworks = [
145+
'bitcoinMainnet',
146+
'bitcoinTestnet',
147+
'liquidMainnet',
148+
'liquidTestnet',
149+
];
150+
for (final network in mempoolNetworks) {
151+
await db
152+
.into(mempoolSettings)
153+
.insertOnConflictUpdate(
154+
RawValuesInsertable({
155+
'network': Constant(network),
156+
'use_for_fee_estimation': const Constant(true),
157+
}),
158+
);
159+
}
105160
}
106161
}

0 commit comments

Comments
 (0)