forked from jaydip12357/DL_Project_1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_database.py
More file actions
61 lines (52 loc) · 1.78 KB
/
setup_database.py
File metadata and controls
61 lines (52 loc) · 1.78 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
"""
Setup script to initialize Supabase database with schema.
Run this once to create all tables.
"""
import os
from dotenv import load_dotenv
from supabase import create_client
# Load environment variables
load_dotenv()
# Get Supabase credentials
SUPABASE_URL = os.getenv('SUPABASE_URL')
SUPABASE_KEY = os.getenv('SUPABASE_KEY')
if not SUPABASE_URL or not SUPABASE_KEY:
print("❌ Error: SUPABASE_URL and SUPABASE_KEY not found in .env")
exit(1)
print("🔗 Connecting to Supabase...")
supabase = create_client(SUPABASE_URL, SUPABASE_KEY)
# Read SQL schema
try:
with open('database_schema.sql', 'r') as f:
sql_script = f.read()
print("✅ Schema file loaded")
except FileNotFoundError:
print("❌ Error: database_schema.sql not found")
exit(1)
# Split SQL statements and execute
print("📊 Creating database tables...")
try:
# Execute the SQL script
response = supabase.postgrest.auth(SUPABASE_KEY).execute_raw_sql(sql_script)
print("✅ Database setup complete!")
print("\nTables created:")
print(" • hospitals")
print(" • users")
print(" • uploads")
print(" • analyses")
print(" • patient_metadata")
print(" • case_summary")
print(" • regional_summary")
print(" • alerts")
print(" • resources")
print("\n✅ Sample data loaded (5 hospitals, 30-day outbreak data)")
print("\nYou're ready to deploy! 🚀")
except Exception as e:
print(f"⚠️ Note: {str(e)}")
print("\nYou can also set up the database manually:")
print("1. Go to https://gdtcnuzanixrmxgedqqp.supabase.co")
print("2. Click SQL Editor → New Query")
print("3. Copy all SQL from database_schema.sql")
print("4. Paste and Run")
print("\nThen you're ready to deploy! 🚀")