Skip to main content
Glama
setup_database.pyβ€’5.19 kB
#!/usr/bin/env python3 """ IRIS Database Setup Script Creates dedicated PostgreSQL user and database for IRIS system. """ import psycopg2 from psycopg2 import sql import secrets import string import sys import os from pathlib import Path # Add src to path for imports sys.path.insert(0, str(Path(__file__).parent.parent / "src")) def generate_secure_password(length: int = 20) -> str: """Generate a cryptographically secure password""" alphabet = string.ascii_letters + string.digits + "!@#$%^&*" return ''.join(secrets.choice(alphabet) for _ in range(length)) def setup_iris_database(): """Setup IRIS database and user""" # Admin connection details admin_config = { "host": "172.17.0.1", "port": "5432", "database": "postgres", "user": "hephaestus", "password": "N0mad2025!Secure" } # Generate secure password for iris_user iris_password = generate_secure_password() try: # Connect as admin print("πŸ”Œ Connecting to PostgreSQL as admin...") conn = psycopg2.connect(**admin_config) conn.autocommit = True cursor = conn.cursor() # Check if iris_user exists cursor.execute("SELECT 1 FROM pg_roles WHERE rolname = %s", ("iris_user",)) user_exists = cursor.fetchone() if not user_exists: print("πŸ‘€ Creating iris_user...") cursor.execute( sql.SQL("CREATE USER {} WITH PASSWORD %s").format( sql.Identifier("iris_user") ), (iris_password,) ) print("βœ… iris_user created successfully") else: print("ℹ️ iris_user already exists") # Check if iris_db exists cursor.execute("SELECT 1 FROM pg_database WHERE datname = %s", ("iris_db",)) db_exists = cursor.fetchone() if not db_exists: print("πŸ—„οΈ Creating iris_db database...") cursor.execute( sql.SQL("CREATE DATABASE {} OWNER {}").format( sql.Identifier("iris_db"), sql.Identifier("iris_user") ) ) print("βœ… iris_db created successfully") else: print("ℹ️ iris_db already exists") # Grant privileges print("πŸ” Setting up permissions...") cursor.execute( sql.SQL("GRANT ALL PRIVILEGES ON DATABASE {} TO {}").format( sql.Identifier("iris_db"), sql.Identifier("iris_user") ) ) cursor.close() conn.close() # Test connection with new user print("πŸ§ͺ Testing connection with iris_user...") test_config = { "host": "172.17.0.1", "port": "5432", "database": "iris_db", "user": "iris_user", "password": iris_password } test_conn = psycopg2.connect(**test_config) test_cursor = test_conn.cursor() test_cursor.execute("SELECT version()") version = test_cursor.fetchone() print(f"βœ… Connection test successful: {version[0]}") test_cursor.close() test_conn.close() # Create .env file with database configuration env_path = Path(__file__).parent.parent / ".env" print(f"πŸ“ Creating .env file at {env_path}") database_url = f"postgresql://iris_user:{iris_password}@172.17.0.1:5432/iris_db" env_content = f"""# IRIS Environment Configuration # Generated by setup_database.py # Database Configuration DATABASE_URL={database_url} REDIS_URL=redis://localhost:6379/0 # Telegram Bot (TO BE CONFIGURED) TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here TELEGRAM_WEBHOOK_URL=https://your-domain.com/webhook/telegram # LLM Configuration (TO BE CONFIGURED) OPENAI_API_KEY=your_openai_api_key ANTHROPIC_API_KEY=your_anthropic_api_key LLM_PROVIDER=openai # Security JWT_SECRET_KEY={generate_secure_password(32)} JWT_ALGORITHM=HS256 JWT_EXPIRATION_HOURS=24 # Application Settings DEBUG=true LOG_LEVEL=INFO ENVIRONMENT=development # Rate Limiting RATE_LIMIT_PER_MINUTE=60 RATE_LIMIT_PER_HOUR=1000 # Webhook Security WEBHOOK_SECRET={generate_secure_password(24)} # Cache Settings CACHE_TTL_SECONDS=3600 EMAIL_CACHE_TTL_SECONDS=1800 CALENDAR_CACHE_TTL_SECONDS=900 """ with open(env_path, "w") as f: f.write(env_content) print("πŸŽ‰ Database setup completed successfully!") print(f"πŸ“‹ Database URL: {database_url}") print(f"πŸ“„ Environment file created: {env_path}") print("\nπŸ”‘ IRIS Database Credentials:") print(f" Host: 172.17.0.1:5432") print(f" Database: iris_db") print(f" User: iris_user") print(f" Password: {iris_password}") return True except Exception as e: print(f"❌ Database setup failed: {e}") return False if __name__ == "__main__": success = setup_iris_database() sys.exit(0 if success else 1)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ilvolodel/iris-legacy'

If you have feedback or need assistance with the MCP directory API, please join our Discord server