-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinit_db.py
More file actions
34 lines (31 loc) · 986 Bytes
/
init_db.py
File metadata and controls
34 lines (31 loc) · 986 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
25
26
27
28
29
30
31
32
33
34
import os
import asyncio
import asyncpg
def get_db_url():
# Try .env first, then environment
if os.path.exists('.env'):
from dotenv import load_dotenv
load_dotenv('.env')
return os.environ.get("SUPABASE_DB_URL")
async def run_schema():
db_url = get_db_url()
if not db_url:
print("SUPABASE_DB_URL not set in environment or .env")
return
schema_path = "docs/supabase_schema.sql"
if not os.path.exists(schema_path):
print(f"Schema file not found: {schema_path}")
return
with open(schema_path, "r") as f:
sql = f.read()
# Split on semicolons, ignore empty statements
statements = [s.strip() for s in sql.split(";") if s.strip()]
conn = await asyncpg.connect(db_url)
try:
for stmt in statements:
await conn.execute(stmt)
print("Schema applied successfully.")
finally:
await conn.close()
if __name__ == "__main__":
asyncio.run(run_schema())