Jelajahi Sumber

apply code review suggestions

Stavros kois 1 tahun lalu
induk
melakukan
1de4b18108
1 mengubah file dengan 14 tambahan dan 23 penghapusan
  1. 14 23
      library/ix-dev/community/immich/migrations/migrate

+ 14 - 23
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