-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_temporal_db.py
More file actions
24 lines (22 loc) · 707 Bytes
/
Copy pathcreate_temporal_db.py
File metadata and controls
24 lines (22 loc) · 707 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import asyncio
import os
import asyncpg
async def main():
url = os.environ.get("DATABASE_URL") # This is pointing to /memu
if not url:
return
# Connect to the default 'postgres' database
base_url = url.rsplit('/', 1)[0] + '/postgres'
print(f"Connecting to {base_url}")
conn = await asyncpg.connect(base_url)
try:
await conn.execute("CREATE DATABASE temporal;")
print("Database 'temporal' created.")
except asyncpg.exceptions.DuplicateDatabaseError:
print("Database 'temporal' already exists.")
except Exception as e:
print(f"Error: {e}")
finally:
await conn.close()
if __name__ == "__main__":
asyncio.run(main())