@@ -237,7 +237,49 @@ async def create_proxy_file_handle():
237237print (f"Base key: { retrieved_storage .base_key } " )
238238
239239
240- # Step 10: Index and migrate files to the new storage location
240+ # Step 10: Update a storage location
241+ #
242+ # Storage locations are immutable in Synapse — individual fields cannot be edited
243+ # after creation. To "update" a storage location, create a new one with the desired
244+ # settings and reassign it to the folder or project.
245+ #
246+ # Example: change the base key of the External S3 storage location used by
247+ # external_s3_folder from MY_BASE_KEY to "synapse-data-v2".
248+
249+ updated_s3_storage_location = StorageLocation (
250+ storage_type = StorageLocationType .EXTERNAL_S3 ,
251+ bucket = MY_BUCKET_NAME ,
252+ base_key = "synapse-data-v2" ,
253+ description = "External S3 storage location (updated base key)" ,
254+ ).store ()
255+
256+ print (f"New storage location ID: { updated_s3_storage_location .storage_location_id } " )
257+
258+ # Reassign the folder to point at the new storage location
259+ external_s3_folder .set_storage_location (
260+ storage_location_id = updated_s3_storage_location .storage_location_id
261+ )
262+ updated_folder_setting = external_s3_folder .get_project_setting ()
263+ assert (
264+ updated_folder_setting ["locations" ][0 ]
265+ == updated_s3_storage_location .storage_location_id
266+ ), "Folder storage location was not updated"
267+
268+ print ("Folder now uses the updated storage location." )
269+
270+ # Step 10b: Partial update — add a storage location without removing existing ones
271+ #
272+ # `set_storage_location` is a destructive replacement. To append a new location
273+ # while keeping the ones already configured, read the current ProjectSetting,
274+ # append to its `locations` list, and call store() on the setting directly.
275+
276+ setting = external_s3_folder .get_project_setting ()
277+ if setting is not None :
278+ setting .locations .append (gcs_storage .storage_location_id )
279+ setting .store ()
280+ print (f"Updated locations after partial update: { setting .locations } " )
281+
282+ # Step 11: Index and migrate files to the new storage location
241283#
242284# WARNING: This will actually migrate files associated with the project/folder.
243285# Run against a test project first and review the index (MigrationResult) before
0 commit comments