Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add database versioning #1489

Merged
merged 6 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/app/env.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
declare namespace NodeJS {
export interface ProcessEnv {
VITE_APP_VERSION: string;
VITE_DATABASE_VERSION: string;
readonly VITE_FUEL_PROVIDER_URL: string;
readonly VITE_FUEL_FAUCET_URL: string;
readonly VITE_MNEMONIC_WORDS: string;
Expand Down
5 changes: 1 addition & 4 deletions packages/app/load.envs.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ function getVersion() {
);
return {
version: packageJson.version,
database: packageJson.database,
};
}

Expand Down Expand Up @@ -38,11 +37,9 @@ function getPublicEnvs() {
);
}

// Export the version to be used on database
// and application level
// Export the version to be used on application level
const versions = getVersion();
process.env.PORT = 3000;
process.env.VITE_APP_VERSION = process.env.VITE_APP_VERSION || versions.version;
process.env.VITE_DATABASE_VERSION = versions.database;

module.exports.getPublicEnvs = getPublicEnvs;
1 change: 0 additions & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "fuels-wallet",
"private": true,
"version": "0.29.0",
"database": "19",
"scripts": {
"build:all": "run-s build:web build:crx build:storybook",
"build:web": "./scripts/build.sh --app=vite",
Expand Down
2 changes: 0 additions & 2 deletions packages/app/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export const {
VITE_FUEL_FAUCET_URL,
VITE_ADDR_OWNER,
VITE_APP_VERSION,
VITE_DATABASE_VERSION,
VITE_CRX_NAME,
VITE_CRX,
VITE_CRX_VERSION_API,
Expand All @@ -19,7 +18,6 @@ export const {
export const EXPLORER_URL = VITE_EXPLORER_URL;
export const WALLET_NAME = VITE_CRX_NAME;
export const APP_VERSION = VITE_APP_VERSION;
export const DATABASE_VERSION = Number(VITE_DATABASE_VERSION);
export const FORMAT_LANGUAGE = 'en-US';
export const MIN_FRACTION_DIGITS = 1;
export const MAX_FRACTION_DIGITS = 3;
Expand Down
39 changes: 2 additions & 37 deletions packages/app/src/systems/Core/utils/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ import type {
import type { DbEvents, PromiseExtended, Table } from 'dexie';
import Dexie from 'dexie';
import 'dexie-observable';
import { CHAIN_IDS, DEVNET_NETWORK_URL, TESTNET_NETWORK_URL } from 'fuels';
import { DATABASE_VERSION } from '~/config';
import type { Transaction } from '~/systems/Transaction/types';
import { applyDbVersioning } from './databaseVersioning';

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

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

constructor() {
super('FuelDB');
this.version(DATABASE_VERSION)
.stores({
vaults: 'key',
accounts: '&address, &name',
networks: '&id, chainId, &url, &name',
connections: 'origin',
transactions: '&id',
assets: '&assetId, &name, &symbol',
abis: '&contractId',
errors: '&id',
})
.upgrade(async (tx) => {
const networks = tx.table('networks');

// Clean networks
await networks.clear();

// Insert testnet network
await networks.add({
chainId: CHAIN_IDS.fuel.testnet,
name: 'Fuel Sepolia Testnet',
url: TESTNET_NETWORK_URL,
isSelected: true,
id: createUUID(),
});

// Insert devnet network
await networks.add({
chainId: CHAIN_IDS.fuel.devnet,
name: 'Fuel Ignition Sepolia Devnet',
url: DEVNET_NETWORK_URL,
isSelected: false,
id: createUUID(),
});
});
applyDbVersioning(this);
this.setupListeners();
}

Expand Down
41 changes: 41 additions & 0 deletions packages/app/src/systems/Core/utils/databaseVersioning.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { createUUID } from '@fuel-wallet/connections';
import type Dexie from 'dexie';
import { CHAIN_IDS, DEVNET_NETWORK_URL, TESTNET_NETWORK_URL } from 'fuels';

export const applyDbVersioning = (db: Dexie) => {
db.version(19)
.stores({
vaults: 'key',
accounts: '&address, &name',
networks: '&id, &url, &name',
connections: 'origin',
transactions: '&id',
assets: '&assetId, &name, &symbol',
abis: '&contractId',
errors: '&id',
})
.upgrade(async (tx) => {
const networks = tx.table('networks');

// Clean networks
await networks.clear();

// Insert testnet network
await networks.add({
chainId: CHAIN_IDS.fuel.testnet,
name: 'Fuel Sepolia Testnet',
url: TESTNET_NETWORK_URL,
isSelected: true,
id: createUUID(),
});

// Insert devnet network
await networks.add({
chainId: CHAIN_IDS.fuel.devnet,
name: 'Fuel Ignition Sepolia Devnet',
url: DEVNET_NETWORK_URL,
isSelected: false,
id: createUUID(),
});
});
};
Loading