From 1de4b181084e2dc2798b36a500d154a58bf23881 Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Fri, 17 Nov 2023 15:09:16 +0200 Subject: [PATCH] apply code review suggestions --- .../community/immich/migrations/migrate | 37 +++++++------------ 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/library/ix-dev/community/immich/migrations/migrate b/library/ix-dev/community/immich/migrations/migrate index 4e5781d2c6..d79c3df168 100644 --- a/library/ix-dev/community/immich/migrations/migrate +++ b/library/ix-dev/community/immich/migrations/migrate @@ -5,41 +5,36 @@ import sys # Used to migrate storage format to include ACLs -def storageMigrate(storage): - delKeys = [] +def storage_migrate(storage): + delete_keys = [] if storage['type'] == 'hostPath': # Check if the key exists, if not we have already migrated if not storage.get('hostPath'): return storage - hostPath = storage['hostPath'] - storage['hostPathConfig'] = { 'hostPath': hostPath } - delKeys.append('hostPath') + storage['hostPathConfig'] = {'hostPath': storage['hostPath']} + delete_keys.append('hostPath') if storage['type'] == 'ixVolume': # Check if the key exists, if not we have already migrated if not storage.get('datasetName'): return storage - datasetName = storage['datasetName'] - storage['ixVolumeConfig'] = { 'datasetName': datasetName } - delKeys.append('datasetName') + storage['ixVolumeConfig'] = {'datasetName': storage['datasetName']} + delete_keys.append('datasetName') - for key in delKeys: + for key in delete_keys: del storage[key] return storage # Used to migrate libraries to additionalStorages -def librariesMigrate(libraries): +def libraries_migrate(libraries): # Additional **Libraries** only had a field for hostPath, because Immich # had a requirement for both hostPath and mountPath to be the same, # now its no longer the case, so we can merge it with additionalStorages for idx, library in enumerate(libraries): - if not isinstance(library, dict) or not library: - continue - libraries[idx].update({ 'type': 'hostPath', 'mountPath': library['hostPath'], @@ -54,25 +49,21 @@ def librariesMigrate(libraries): def migrate(values): - storageKey = 'immichStorage' + storage_key = 'immichStorage' storages = ['uploads', 'library', 'thumbs', 'profile', 'video', 'pgData', 'pgBackup'] for storage in storages: - check_val = values.get(storageKey, {}).get(storage, {}) - if not isinstance(check_val, dict) or not check_val: - continue - - values[storageKey][storage] = storageMigrate(check_val) + values[storage_key][storage] = storage_migrate(values[storage_key][storage]) # Migrate additionalLibraries, # if additionalLibraries does not exist, we have already migrated - if libraries := values.get(storageKey, {}).get('additionalLibraries'): + if libraries := values[storage_key].get('additionalLibraries', []): # If additionalLibraries exists, additionalStorages does not exist yet - values[storageKey].update({ - 'additionalStorages': librariesMigrate(libraries) + values[storage_key].update({ + 'additionalStorages': libraries_migrate(libraries) }) - del values[storageKey]['additionalLibraries'] + del values[storage_key]['additionalLibraries'] return values