File tree 2 files changed +35
-0
lines changed
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -302,6 +302,28 @@ def check_quota(self, library):
302
302
l = ArcticLibraryBinding (self , library )
303
303
l .check_quota ()
304
304
305
+ def rename_library (self , from_lib , to_lib ):
306
+ """
307
+ Renames a library
308
+
309
+ Parameters
310
+ ----------
311
+ from_lib: str
312
+ The name of the library to be renamed
313
+ to_lib: str
314
+ The new name of the library
315
+ """
316
+ l = ArcticLibraryBinding (self , from_lib )
317
+ colname = l .get_top_level_collection ().name
318
+ logger .info ('Dropping collection: %s' % colname )
319
+ l ._db [colname ].rename (to_lib )
320
+ for coll in l ._db .collection_names ():
321
+ if coll .startswith (colname + '.' ):
322
+ l ._db [coll ].rename (coll .replace (from_lib , to_lib ))
323
+ if from_lib in self ._library_cache :
324
+ del self ._library_cache [from_lib ]
325
+ del self ._library_cache [l .get_name ()]
326
+
305
327
306
328
class ArcticLibraryBinding (object ):
307
329
"""
Original file line number Diff line number Diff line change @@ -144,3 +144,16 @@ def test_default_mongo_retry_timout():
144
144
with pytest .raises (LibraryNotFoundException ):
145
145
Arctic ('unresolved-host' , serverSelectionTimeoutMS = 0 )['some.lib' ]
146
146
assert time .time () - now < 1.
147
+
148
+
149
+ def test_lib_rename (arctic ):
150
+ arctic .initialize_library ('test' )
151
+ l = arctic ['test' ]
152
+ l .write ('test_data' , 'abc' )
153
+ arctic .rename_library ('test' , 'new_name' )
154
+ l = arctic ['new_name' ]
155
+ assert (l .read ('test_data' ).data == 'abc' )
156
+ with pytest .raises (LibraryNotFoundException ) as e :
157
+ l = arctic ['test' ]
158
+ assert ('Library test' in str (e ))
159
+ assert ('test' not in arctic .list_libraries ())
You can’t perform that action at this time.
0 commit comments