rsnarsna commited on
Commit ·
cab8aa3
1
Parent(s): ad257ce
Add python-dotenv and DB test script
Browse files- requirements.txt +1 -0
- test_db.py +26 -0
requirements.txt
CHANGED
|
@@ -7,3 +7,4 @@ django-q2>=1.10.0
|
|
| 7 |
jinja2
|
| 8 |
whitenoise
|
| 9 |
gunicorn
|
|
|
|
|
|
| 7 |
jinja2
|
| 8 |
whitenoise
|
| 9 |
gunicorn
|
| 10 |
+
python-dotenv
|
test_db.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import psycopg2
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
print("Loading environment variables...")
|
| 6 |
+
# Load environment variables from .env
|
| 7 |
+
load_dotenv()
|
| 8 |
+
|
| 9 |
+
# Fetch variables
|
| 10 |
+
DATABASE_URL = os.getenv("DATABASE_URL")
|
| 11 |
+
if not DATABASE_URL:
|
| 12 |
+
print("No DATABASE_URL found in .env! Using Supabase URL directly for test.")
|
| 13 |
+
DATABASE_URL = "postgresql://postgres:ngbksZaNkjulikrp@db.tyhlrlpebsgcciglxonc.supabase.co:5432/postgres"
|
| 14 |
+
|
| 15 |
+
print("Connecting to the database...")
|
| 16 |
+
try:
|
| 17 |
+
# Connect to the database
|
| 18 |
+
connection = psycopg2.connect(DATABASE_URL)
|
| 19 |
+
print("SUCCESS! Database connection string works perfectly!")
|
| 20 |
+
|
| 21 |
+
# Close connection
|
| 22 |
+
connection.close()
|
| 23 |
+
except Exception as e:
|
| 24 |
+
print("FAILED to connect!")
|
| 25 |
+
print("Error:", e)
|
| 26 |
+
print("\nReminder: Vercel does not support IPv6. If this URL works locally but fails on Vercel, you MUST use the IPv4 Connection Pooler URL from Supabase!")
|