Skip to content

Commit

Permalink
Don't crash while migrating the database when a radiogram is missing (h…
Browse files Browse the repository at this point in the history
…pi-sam#899)

Bump version number

Add a changelog entry

Update changelog

Fix linter

Add dot to changelog

Update package-log accordingly
  • Loading branch information
Greenscreen23 authored Apr 21, 2023
1 parent c3e074e commit cf88ab5
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 49 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project does **not** adhere to [Semantic Versioning](https://semver.org

## [Unreleased]

## [0.4.1] - 2023-04-20

### Fixed

- Added a guard clause to handle exercises with radiogram actions containing incorrect uuids.
- Fixed deletion of invalid actions in the database.

## [0.4.0] - 2023-04-19

### Added
Expand Down
6 changes: 3 additions & 3 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "digital-fuesim-manv-backend",
"version": "0.4.0",
"version": "0.4.1",
"type": "module",
"scripts": {
"start:once:linux-macos": "NODE_ENV=production node --experimental-specifier-resolution=node dist/src/index.js",
Expand Down
66 changes: 38 additions & 28 deletions backend/src/database/migrate-in-database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,39 +61,49 @@ export async function migrateInDatabase(
newIndex: number;
actionString: string;
}[] = [];
actions.forEach((action, i) => {
if (action === null) {
indicesToRemove.push(i);
return;
}
actionsToUpdate.push({
previousIndex: i,
newIndex: patchedActionsIndex++,
actionString: JSON.stringify(action),
if (actions.length > 0) {
actions.forEach((action, i) => {
if (action === null) {
indicesToRemove.push(i);
return;
}
actionsToUpdate.push({
previousIndex: i,
newIndex: patchedActionsIndex++,
actionString: JSON.stringify(action),
});
});
});
if (indicesToRemove.length > 0) {
if (indicesToRemove.length > 0) {
await entityManager
.createQueryBuilder()
.delete()
.from(ActionWrapperEntity)
// eslint-disable-next-line unicorn/string-content
.where('index IN (:...ids)', { ids: indicesToRemove })
.andWhere({ exercise: { id: exerciseId } })
.execute();
}
if (actionsToUpdate.length > 0) {
await Promise.all(
actionsToUpdate.map(
async ({ previousIndex, newIndex, actionString }) =>
entityManager.update(
ActionWrapperEntity,
{
index: previousIndex,
exercise: { id: exerciseId },
},
{ actionString, index: newIndex }
)
)
);
}
} else {
await entityManager
.createQueryBuilder()
.delete()
.from(ActionWrapperEntity)
// eslint-disable-next-line unicorn/string-content
.where('index IN (:...ids)', { ids: indicesToRemove })
.where({ exercise: { id: exerciseId } })
.execute();
}
if (actionsToUpdate.length > 0) {
await Promise.all(
actionsToUpdate.map(
async ({ previousIndex, newIndex, actionString }) =>
entityManager.update(
ActionWrapperEntity,
{
index: previousIndex,
exercise: { id: exerciseId },
},
{ actionString, index: newIndex }
)
)
);
}
}
6 changes: 3 additions & 3 deletions benchmark/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "digital-fuesim-manv-benchmark",
"version": "0.4.0",
"version": "0.4.1",
"type": "module",
"scripts": {
"lint": "eslint --max-warnings 0 --ignore-path .gitignore \"./**/*.{ts,js,yml,html}\"",
Expand Down
2 changes: 1 addition & 1 deletion docs/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ openapi: 3.0.3
info:
title: Digital Fuesim MANV HTTP API
description: HTTP API of the digital-fuesim-manv project
version: 0.4.0
version: 0.4.1
paths:
/api/health:
get:
Expand Down
6 changes: 3 additions & 3 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "digital-fuesim-manv-frontend",
"version": "0.4.0",
"version": "0.4.1",
"type": "module",
"scripts": {
"cy:open": "cypress open",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "digital-fuesim-manv",
"version": "0.4.0",
"version": "0.4.1",
"type": "module",
"scripts": {
"build": "cd shared && npm run build && cd .. && concurrently \"cd frontend && npm run build\" \"cd backend && npm run build\"",
Expand Down
4 changes: 2 additions & 2 deletions shared/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "digital-fuesim-manv-shared",
"version": "0.4.0",
"version": "0.4.1",
"type": "module",
"main": "./dist/index.js",
"esnext": "./dist/index.js",
Expand Down
15 changes: 13 additions & 2 deletions shared/src/models/radiogram/radiogram-helpers-mutable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ExerciseState } from '../../state';
import { ReducerError } from '../../store/reducer-error';
import type { Mutable, UUID } from '../../utils';
import type { ExerciseRadiogram } from './exercise-radiogram';
import { publishTimeOf } from './radiogram-helpers';
Expand All @@ -19,7 +20,12 @@ export function acceptRadiogram(
radiogramId: UUID,
clientId: UUID
) {
const radiogram = draftState.radiograms[radiogramId]!;
const radiogram = draftState.radiograms[radiogramId];
if (!radiogram) {
throw new ReducerError(
`Expected to find radiogram with id ${radiogramId}, but there was none`
);
}
radiogram.status = {
type: 'acceptedRadiogramStatus',
publishTime: publishTimeOf(radiogram),
Expand All @@ -31,7 +37,12 @@ export function markRadiogramDone(
draftState: Mutable<ExerciseState>,
radiogramId: UUID
) {
const radiogram = draftState.radiograms[radiogramId]!;
const radiogram = draftState.radiograms[radiogramId];
if (!radiogram) {
throw new ReducerError(
`Expected to find radiogram with id ${radiogramId}, but there was none`
);
}
radiogram.status = {
type: 'doneRadiogramStatus',
publishTime: publishTimeOf(radiogram),
Expand Down

0 comments on commit cf88ab5

Please sign in to comment.