Skip to content

Commit

Permalink
migrations: Add a starting migration script
Browse files Browse the repository at this point in the history
It initially contains the renaming migrations of localStorage keys
  • Loading branch information
rafaellehmkuhl committed Feb 3, 2025
1 parent cc8a9cc commit 89c1667
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ import VueVirtualScroller from 'vue-virtual-scroller'

import { app_version } from '@/libs/cosmos'
import eventTracker from '@/libs/external-telemetry/event-tracking'
import { runMigrations } from '@/utils/migrations'

import App from './App.vue'
import vuetify from './plugins/vuetify'
import { loadFonts } from './plugins/webfontloader'
import router from './router'
import { useOmniscientLoggerStore } from './stores/omniscientLogger'

// Run migrations that are needed for the app to work
runMigrations()

library.add(fas, far)
loadFonts()

Expand Down
24 changes: 24 additions & 0 deletions src/utils/migrations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Migrate old localStorage keys to new ones
*/
const migrateRenameOfLocalStorageKeys = (): void => {
const oldToNewKeys = {
'main-menu-style': 'cockpit-main-menu-style',
'last-tutorial-step': 'cockpit-last-tutorial-step',
'tutorial-modal': 'cockpit-tutorial-modal',
}
Object.entries(oldToNewKeys).forEach(([oldKey, newKey]) => {
const oldValue = localStorage.getItem(oldKey)
if (oldValue !== null) {
localStorage.setItem(newKey, oldValue)
localStorage.removeItem(oldKey)
}
})
}

/**
* Run all migrations
*/
export function runMigrations(): void {
migrateRenameOfLocalStorageKeys()
}

0 comments on commit 89c1667

Please sign in to comment.