@@ -34,6 +34,8 @@ def migrate_schema(
3434 db_name = collection_config .db_name
3535 collection_name = collection_config .collection_name
3636
37+ print (f"\n Migrating schema for collection: { db_name } .{ collection_name } " )
38+
3739 source_db = source_client [db_name ]
3840 source_collection = source_db [collection_name ]
3941
@@ -42,20 +44,29 @@ def migrate_schema(
4244
4345 # Check if the destination collection should be dropped
4446 if collection_config .drop_if_exists :
47+ print ("-- Running drop command on target collection" )
4548 dest_collection .drop ()
4649
4750 # Create the destination collection if it doesn't exist
4851 if not collection_name in dest_db .list_collection_names ():
52+ print ("-- Creating target collection" )
4953 dest_db .create_collection (collection_name )
54+ else :
55+ print ("-- Target collection already exists. Skipping creation." )
5056
5157 # Check if shard key should be created
5258 if collection_config .migrate_shard_key :
5359 source_shard_key = self ._get_shard_key_ru (source_db , collection_config )
5460 if (source_shard_key is not None ):
61+ print (f"-- Migrating shard key - { source_shard_key } ." )
5562 dest_client .admin .command (
5663 "shardCollection" ,
5764 f"{ db_name } .{ collection_name } " ,
5865 key = source_shard_key )
66+ else :
67+ print (f"-- No shard key found for collection { collection_name } . Skipping shard key setup." )
68+ else :
69+ print ("-- Skipping shard key migration for collection" )
5970
6071 # Migrate indexes
6172 index_list = []
@@ -67,11 +78,14 @@ def migrate_schema(
6778 index_list .append ((index_keys , index_options ))
6879
6980 if collection_config .optimize_compound_indexes :
81+ print ("-- Optimizing compound indexes if available" )
7082 index_list = self ._optimize_compound_indexes (index_list )
7183
84+ print ("-- Migrating indexes for collection" )
7285 for index_keys , index_options in index_list :
7386 if self ._is_ts_ttl_index (index_keys , index_options ):
7487 raise ValueError (f"Cannot migrate TTL index on _ts field for collection { collection_name } ." )
88+ print (f"---- Creating index: { index_keys } with options: { index_options } " )
7589 dest_collection .create_index (index_keys , ** index_options )
7690
7791 def _get_shard_key_ru (self , source_db : Database , collection_config : CollectionConfig ):
0 commit comments