Skip to content

Commit 9f4334c

Browse files
authored
feat: add database versioning (#1489)
- Closes #1490
1 parent 48d4df4 commit 9f4334c

File tree

3 files changed

+51
-37
lines changed

3 files changed

+51
-37
lines changed

.changeset/strong-falcons-worry.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@fuel-wallet/connections": patch
3+
"@fuel-wallet/types": patch
4+
"fuels-wallet": patch
5+
"@fuels/playwright-utils": patch
6+
---
7+
8+
feat: add db versioning

packages/app/src/systems/Core/utils/database.ts

+2-37
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ import type {
1212
import type { DbEvents, PromiseExtended, Table } from 'dexie';
1313
import Dexie from 'dexie';
1414
import 'dexie-observable';
15-
import { CHAIN_IDS, DEVNET_NETWORK_URL, TESTNET_NETWORK_URL } from 'fuels';
16-
import { DATABASE_VERSION } from '~/config';
1715
import type { Transaction } from '~/systems/Transaction/types';
16+
import { applyDbVersioning } from './databaseVersioning';
1817

1918
type FailureEvents = Extract<keyof DbEvents, 'close' | 'blocked'>;
2019

@@ -33,41 +32,7 @@ export class FuelDB extends Dexie {
3332

3433
constructor() {
3534
super('FuelDB');
36-
this.version(DATABASE_VERSION)
37-
.stores({
38-
vaults: 'key',
39-
accounts: '&address, &name',
40-
networks: '&id, chainId, &url, &name',
41-
connections: 'origin',
42-
transactions: '&id',
43-
assets: '&assetId, &name, &symbol',
44-
abis: '&contractId',
45-
errors: '&id',
46-
})
47-
.upgrade(async (tx) => {
48-
const networks = tx.table('networks');
49-
50-
// Clean networks
51-
await networks.clear();
52-
53-
// Insert testnet network
54-
await networks.add({
55-
chainId: CHAIN_IDS.fuel.testnet,
56-
name: 'Fuel Sepolia Testnet',
57-
url: TESTNET_NETWORK_URL,
58-
isSelected: true,
59-
id: createUUID(),
60-
});
61-
62-
// Insert devnet network
63-
await networks.add({
64-
chainId: CHAIN_IDS.fuel.devnet,
65-
name: 'Fuel Ignition Sepolia Devnet',
66-
url: DEVNET_NETWORK_URL,
67-
isSelected: false,
68-
id: createUUID(),
69-
});
70-
});
35+
applyDbVersioning(this);
7136
this.setupListeners();
7237
}
7338

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { createUUID } from '@fuel-wallet/connections';
2+
import type Dexie from 'dexie';
3+
import { CHAIN_IDS, DEVNET_NETWORK_URL, TESTNET_NETWORK_URL } from 'fuels';
4+
5+
export const applyDbVersioning = (db: Dexie) => {
6+
db.version(19)
7+
.stores({
8+
vaults: 'key',
9+
accounts: '&address, &name',
10+
networks: '&id, &url, &name',
11+
connections: 'origin',
12+
transactions: '&id',
13+
assets: '&assetId, &name, &symbol',
14+
abis: '&contractId',
15+
errors: '&id',
16+
})
17+
.upgrade(async (tx) => {
18+
const networks = tx.table('networks');
19+
20+
// Clean networks
21+
await networks.clear();
22+
23+
// Insert testnet network
24+
await networks.add({
25+
chainId: CHAIN_IDS.fuel.testnet,
26+
name: 'Fuel Sepolia Testnet',
27+
url: TESTNET_NETWORK_URL,
28+
isSelected: true,
29+
id: createUUID(),
30+
});
31+
32+
// Insert devnet network
33+
await networks.add({
34+
chainId: CHAIN_IDS.fuel.devnet,
35+
name: 'Fuel Ignition Sepolia Devnet',
36+
url: DEVNET_NETWORK_URL,
37+
isSelected: false,
38+
id: createUUID(),
39+
});
40+
});
41+
};

0 commit comments

Comments
 (0)