Skip to content

Commit

Permalink
Account for No Windows when Migrating Queries (#1387)
Browse files Browse the repository at this point in the history
* account for no windows in the migration

* Only migrate data if there is data
  • Loading branch information
jameskerr authored Jan 26, 2021
1 parent 5200b99 commit 1e67547
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/js/electron/tron/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default async function migrations(

run(state: VersionedData, migrations: Migration[]) {
for (const {version, migrate} of migrations) {
state.data = migrate(state.data)
state.data = state.data ? migrate(state.data) : undefined
state.version = version
}
return state
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import getTestState from "../../test/helpers/getTestState"
import migrate from "./202101201109_moveQueriesStateToGlobal"

test("when there are no windows", () => {
const {data} = getTestState("v0.22.0")
data.windows = {}
data.order = []
const next = migrate(data)
expect(next.globalState.queries).toBe(undefined)
})

test("migrating 202101201109_moveQueriesStateToGlobal", () => {
let {data} = getTestState("v0.22.0")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ export default function moveQueriesStateToGlobal(state: any) {
// Migrate state here
const mergedQueryMap = {}
const mergedQueryItems = []
const windows = Object.values(state.windows)

if (windows.length === 0) {
state.globalState.queries = undefined
return state
}

for (const s of getAllStates(state)) {
if (!s.queries) continue
s.queries.items.forEach((q) => {
Expand Down

0 comments on commit 1e67547

Please sign in to comment.