Skip to content

Commit dad9aa5

Browse files
Merge pull request #7 from srwshkrshnn/main
Added logging statements
2 parents 9b0f309 + 1f8ebca commit dad9aa5

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Before running the assessment, ensure that the client machine meets the followin
3636
"*"
3737
],
3838
"exclude": [],
39-
"unsharded": "false",
39+
"migrate_shard_key": "false",
4040
"drop_if_exists": "true",
4141
"optimize_compound_indexes": "true"
4242
}
@@ -55,7 +55,7 @@ Before running the assessment, ensure that the client machine meets the followin
5555
"exclude": [
5656
"db1.*"
5757
],
58-
"unsharded": "false",
58+
"migrate_shard_key": "false",
5959
"drop_if_exists": "true",
6060
"optimize_compound_indexes": "true"
6161
}
@@ -76,7 +76,7 @@ Before running the assessment, ensure that the client machine meets the followin
7676
"db1.coll1",
7777
"db2.coll2"
7878
],
79-
"unsharded": "false",
79+
"migrate_shard_key": "false",
8080
"drop_if_exists": "true",
8181
"optimize_compound_indexes": "true"
8282
}
@@ -94,7 +94,7 @@ Before running the assessment, ensure that the client machine meets the followin
9494
"db1.coll1",
9595
"db2.coll2"
9696
],
97-
"unsharded": "false",
97+
"migrate_shard_key": "false",
9898
"drop_if_exists": "true",
9999
"optimize_compound_indexes": "true"
100100
}
@@ -115,7 +115,7 @@ Before running the assessment, ensure that the client machine meets the followin
115115
"db1.coll1",
116116
"db2.coll2"
117117
],
118-
"unsharded": "false",
118+
"migrate_shard_key": "false",
119119
"drop_if_exists": "true",
120120
"optimize_compound_indexes": "true"
121121
},
@@ -124,7 +124,7 @@ Before running the assessment, ensure that the client machine meets the followin
124124
"db1.coll1",
125125
"db2.coll2"
126126
],
127-
"unsharded": "false",
127+
"migrate_shard_key": "true",
128128
"drop_if_exists": "true",
129129
"optimize_compound_indexes": "true"
130130
}

schema_migration.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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"\nMigrating 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

Comments
 (0)