import asyncio import asyncpg async def setup_db(): try: # Connect to default postgres DB conn = await asyncpg.connect("postgresql://postgres:postgres@localhost:5432/postgres") # Check if sibu exists dbs = await conn.fetch("SELECT datname FROM pg_database WHERE datname = 'sibu'") if not dbs: print("Creating database 'sibu'...") # We can't run CREATE DATABASE inside a transaction await conn.execute("CREATE DATABASE sibu") print("Database 'sibu' created!") else: print("Database 'sibu' already exists.") await conn.close() except Exception as e: print(f"Error: {e}") if __name__ == "__main__": asyncio.run(setup_db())