added encryption

This commit is contained in:
2026-03-09 10:54:07 +05:30
parent 6e184dc590
commit 6720e28d08
27 changed files with 2093 additions and 709 deletions

View File

@@ -15,18 +15,18 @@ from typing import Dict, List, Tuple
def create_indexes():
"""Create all required MongoDB indexes."""
settings = get_settings()
client = MongoClient(settings.mongodb_uri)
db = client[settings.mongodb_db_name]
print(f"✓ Connected to MongoDB: {settings.mongodb_db_name}\n")
indexes_created = []
# ========== USERS COLLECTION INDEXES ==========
print("Creating indexes for 'users' collection...")
# Unique index on email
try:
db.users.create_index(
@@ -38,7 +38,7 @@ def create_indexes():
print(" ✓ Created unique index on email")
except Exception as e:
print(f" ⚠ Email index: {e}")
# Index on createdAt for sorting
try:
db.users.create_index(
@@ -49,10 +49,10 @@ def create_indexes():
print(" ✓ Created index on createdAt")
except Exception as e:
print(f" ⚠ createdAt index: {e}")
# ========== ENTRIES COLLECTION INDEXES ==========
print("\nCreating indexes for 'entries' collection...")
# Compound index: userId + createdAt (for history pagination)
try:
db.entries.create_index(
@@ -63,7 +63,7 @@ def create_indexes():
print(" ✓ Created compound index on (userId, createdAt)")
except Exception as e:
print(f" ⚠ userId_createdAt index: {e}")
# Compound index: userId + entryDate (for calendar queries)
try:
db.entries.create_index(
@@ -74,7 +74,7 @@ def create_indexes():
print(" ✓ Created compound index on (userId, entryDate)")
except Exception as e:
print(f" ⚠ userId_entryDate index: {e}")
# Index on tags for searching (optional, for future)
try:
db.entries.create_index(
@@ -85,7 +85,7 @@ def create_indexes():
print(" ✓ Created index on tags")
except Exception as e:
print(f" ⚠ tags index: {e}")
# Index on entryDate range queries (for calendar)
try:
db.entries.create_index(
@@ -96,7 +96,7 @@ def create_indexes():
print(" ✓ Created index on entryDate")
except Exception as e:
print(f" ⚠ entryDate index: {e}")
# TTL Index on entries (optional: for auto-deleting old entries if needed)
# Uncomment if you want entries to auto-delete after 2 years
# try:
@@ -108,7 +108,7 @@ def create_indexes():
# print(" ✓ Created TTL index on createdAt (2 years)")
# except Exception as e:
# print(f" ⚠ TTL index: {e}")
# ========== SUMMARY ==========
print(f"\n{'='*60}")
print(f"✓ Index Creation Complete")
@@ -116,18 +116,18 @@ def create_indexes():
print(f"Total indexes created: {len(indexes_created)}")
for collection, index_name in indexes_created:
print(f"{collection}.{index_name}")
# Optional: Print summary of all indexes
print(f"\n{'='*60}")
print("All Indexes Summary")
print(f"{'='*60}")
for collection_name in ["users", "entries"]:
print(f"\n{collection_name}:")
collection = db[collection_name]
for index_info in collection.list_indexes():
print(f"{index_info['name']}")
client.close()
print("\n✓ Disconnected from MongoDB")