-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup_database.py
More file actions
66 lines (53 loc) · 1.94 KB
/
setup_database.py
File metadata and controls
66 lines (53 loc) · 1.94 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
62
63
64
65
66
#!/usr/bin/env python3
"""
Setup script to initialize Supabase database with schema.
Run this once to create all tables.
AI Attribution: This file was developed with assistance from Claude (Anthropic).
https://claude.ai
"""
import os
from dotenv import load_dotenv
from supabase import create_client
def main():
"""Initialize the Supabase database using the SQL schema file."""
load_dotenv()
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")
return
print("Connecting to Supabase...")
supabase = create_client(supabase_url, supabase_key)
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")
return
print("Creating database tables...")
try:
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("\nSample 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 your Supabase project dashboard")
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!")
if __name__ == '__main__':
main()