Atlas / scripts /deployment /create_user_indexes.py
findEthics
Complete codebase cleanup and project structure validation
f0b765c
Raw
History Blame Contribute Delete
2.67 kB
#!/usr/bin/env python3
"""
Standalone script to create database indexes for user authentication feature.
Usage:
python create_user_indexes.py [command]
Commands:
create - Create all user_id indexes (default)
verify - Verify indexes exist
list - List all indexes
rollback - Drop all user_id indexes
This script can be run safely on existing data and multiple times.
"""
import asyncio
import logging
import sys
from dotenv import load_dotenv
from analytics.create_indexes import create_user_id_indexes, drop_user_id_indexes, list_all_indexes, verify_indexes
create_user_id_indexes,
verify_indexes,
list_all_indexes,
drop_user_id_indexes
)
def setup_logging():
"""Setup logging configuration"""
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
async def main():
"""Main CLI function"""
setup_logging()
# Get command from arguments
command = sys.argv[1] if len(sys.argv) > 1 else "create"
print(f"πŸš€ User Authentication Index Management")
print(f"Command: {command}")
print("-" * 50)
try:
if command == "create":
print("Creating user_id indexes...")
success = await create_user_id_indexes()
if success:
print("βœ… All indexes created successfully!")
await verify_indexes()
else:
print("❌ Some indexes failed to create. Check logs.")
sys.exit(1)
elif command == "verify":
print("Verifying user_id indexes...")
success = await verify_indexes()
if success:
print("βœ… All indexes verified!")
else:
print("❌ Some indexes are missing.")
sys.exit(1)
elif command == "list":
print("Listing all indexes...")
await list_all_indexes()
elif command == "rollback":
print("Rolling back user_id indexes...")
success = await drop_user_id_indexes()
if success:
print("βœ… Rollback completed!")
else:
print("❌ Rollback failed. Check logs.")
sys.exit(1)
else:
print(f"❌ Unknown command: {command}")
print("Available commands: create, verify, list, rollback")
sys.exit(1)
except Exception as e:
print(f"❌ Script failed: {e}")
sys.exit(1)
if __name__ == "__main__":
asyncio.run(main())