Skip to content

Commit

Permalink
fix: migrations version handling as numeric values
Browse files Browse the repository at this point in the history
  • Loading branch information
olzzon committed Mar 25, 2021
1 parent 8fcb9e4 commit 95b80d5
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions server/utils/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ const path = require('path')

import { logger } from './logger'
import { ISettings } from '../reducers/settingsReducer'
import { getSnapShotList, IShotStorage, saveSettings } from './SettingsStorage'
import { getSnapShotList, IShotStorage } from './SettingsStorage'

const version = process.env.npm_package_version

export const checkVersion = (currentSettings: ISettings): ISettings => {
if (version > (currentSettings.sisyfosVersion || '0')) {
if (
versionAsNumber(version) >
versionAsNumber(currentSettings.sisyfosVersion)
) {
currentSettings = migrateVersion(currentSettings)
}
return currentSettings
Expand All @@ -22,13 +25,13 @@ const migrateVersion = (currentSettings: ISettings): ISettings => {
version
)
let newSettings = currentSettings
if (version === '4.6.0') {
newSettings = migrate45to46(currentSettings)
if (versionAsNumber(version) >= versionAsNumber('4.7.0')) {
newSettings = migrate45to47(currentSettings)
}
return newSettings
}

const migrate45to46 = (currentSettings: ISettings): ISettings => {
const migrate45to47 = (currentSettings: ISettings): ISettings => {
let files: string[] = getSnapShotList()
files.push('default.shot')

Expand Down Expand Up @@ -81,3 +84,12 @@ const migrate45to46 = (currentSettings: ISettings): ISettings => {
)
return currentSettings
}

const versionAsNumber = (versionString: string): number => {
if (!versionString) return 0
let versionArray: string[] = versionString.split('.')
let versionValue: number =
parseInt(versionArray[0]) * 100 + parseInt(versionArray[1])

return versionValue
}

0 comments on commit 95b80d5

Please sign in to comment.