Skip to content

Commit

Permalink
- Added extra tests to check if database migration was successful.
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterBlenessy committed Oct 12, 2023
1 parent 0f55d5e commit acc1fe5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [UNRELEASED]

## v0.25.3 - 2023-10-12
- Added extra tests to check if database migration was successful.

## v0.25.2 - 2023-10-12
- Added extra tests for database migration and also error notifications.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "team-ai",
"private": true,
"version": "0.25.2",
"version": "0.25.3",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
20 changes: 14 additions & 6 deletions src/services/databaseUpgrader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useQuasar } from 'quasar';
import { useI18n } from 'vue-i18n';
import { useTeamsStore } from '../stores/teams-store.js';
import { storeToRefs } from 'pinia';
import { imageDB, settingsDB } from '../services/localforage.js';
import { imageDB, settingsDB, teamsDB } from '../services/localforage.js';

const databaseUpgrader = () => {

Expand All @@ -20,18 +20,18 @@ const databaseUpgrader = () => {
upgrade: () => {}
},
{
version: 4,
version: 5,
description: 'Optimized database structure by moving images from messages to separate table.',
caption: t('databaseUpgrade.inProgress.caption', { version: '4' }),
upgrade: () => upgradeToVersion4()
caption: t('databaseUpgrade.inProgress.caption', { version: '5' }),
upgrade: () => upgradeToVersion5()
}

];

// =================================================================================================
// Update latest database version here when needed
// -------------------------------------------------------------------------------------------------
const LATEST_DB_VERSION = 4;
const LATEST_DB_VERSION = 5;
// =================================================================================================

const getDBVersion = async () => parseInt(JSON.parse(await settingsDB.getItem('dBVersion')));
Expand All @@ -48,7 +48,7 @@ const databaseUpgrader = () => {

// Upgrade to mitigate performance issues due to images being stored in message objects.
// This upgrade moves images to a separate table, imageDB.
const upgradeToVersion4 = () => {
const upgradeToVersion5 = async () => {
if (messages.value.length == 0) {
console.log("No messages to upgrade.");
return;
Expand Down Expand Up @@ -105,6 +105,14 @@ const databaseUpgrader = () => {
}
return message;
});

await teamsDB.setItem('messages', JSON.stringify(messages.value));
const testMessages = await teamsDB.getItem('messages');
if (testMessages != null && testMessages == JSON.stringify(messages.value)) {
console.log("Messages upgrade completed successfully.");
} else {
throw new Error("Error when upgrading messages.");
}
}

// Upgrade database
Expand Down

0 comments on commit acc1fe5

Please sign in to comment.