Migrate from iot.eclipse.org to mqtt.eclipse.org

This commit is contained in:
Thomas Nordquist
2019-06-16 21:23:22 +02:00
parent 0b067bd964
commit 7036d6c8fe
2 changed files with 30 additions and 7 deletions

View File

@@ -166,16 +166,38 @@ export const deleteConnection = (connectionId: string) => (dispatch: Dispatch<an
}
async function ensureConnectionsHaveBeenInitialized() {
const connections = await persistentStorage.load(storedConnectionsIdentifier)
let connections = await persistentStorage.load(storedConnectionsIdentifier)
const requiresInitialization = !connections
if (requiresInitialization) {
const migratedConnection = loadLegacyConnectionOptions()
const defaultConnections = makeDefaultConnections()
persistentStorage.store(storedConnectionsIdentifier, {
connections = {
...migratedConnection,
...defaultConnections,
})
}
await persistentStorage.store(storedConnectionsIdentifier, connections)
clearLegacyConnectionOptions()
}
// Migrate connections, rewrite dictionary to "keep" it "ordered" (dictionaries do not have a guaranteed order)
const mayNeedMigrations = connections && connections['iot.eclipse.org']
if (connections && mayNeedMigrations) {
let newConnections = {}
for (const connection of Object.values(connections)) {
addMigratedConnection(newConnections, connection)
}
await persistentStorage.store(storedConnectionsIdentifier, newConnections)
}
}
function addMigratedConnection(newConnections: { [key: string]: ConnectionOptions }, connection: ConnectionOptions) {
// The host has been renamed, only change the host if it has not been changed
if (connection.id === 'iot.eclipse.org' && connection.host === 'iot.eclipse.org') {
connection.id = 'mqtt.eclipse.org'
connection.host = 'mqtt.eclipse.org'
connection.name = 'mqtt.eclipse.org'
}
newConnections[connection.id] = connection
}