-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto_migrate.py
More file actions
64 lines (54 loc) · 2.87 KB
/
auto_migrate.py
File metadata and controls
64 lines (54 loc) · 2.87 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
import os
import django
from django.core.management import execute_from_command_line
import socket
def run_migrations():
"""Run migrations automatically when the server starts"""
try:
print("Running database migrations...")
# Check if we're in production
if os.environ.get('DJANGO_DEBUG', 'True').lower() == 'false':
# Debug environment variables - use os.environ directly in production
db_host = os.environ.get('DB_HOST', 'localhost')
db_user = os.environ.get('DB_USER', 'dbsocialhub_user')
db_password = os.environ.get('DB_PASSWORD', '')
print(f"DB_HOST: {db_host}")
print(f"DB_USER: {db_user}")
print(f"DB_NAME: {os.environ.get('DB_NAME', 'dbsocialhub')}")
print(f"DB_PORT: {os.environ.get('DB_PORT', '5432')}")
print(f"DB_PASSWORD length: {len(db_password)}")
if db_password:
print(f"DB_PASSWORD first char: '{db_password[0]}'")
print(f"DB_PASSWORD last char: '{db_password[-1]}'")
print(f"DB_PASSWORD repr: {repr(db_password)}")
# Test with the exact password you provided
expected_password = "ThskOnLy0KKXqRjK3MyAv1STbF7DDgos"
print(f"Expected password: {repr(expected_password)}")
print(f"Passwords match: {db_password == expected_password}")
# Show character by character comparison
if len(db_password) == len(expected_password):
for i, (actual, expected) in enumerate(zip(db_password, expected_password)):
if actual != expected:
print(f"Difference at position {i}: got '{actual}' (ord {ord(actual)}), expected '{expected}' (ord {ord(expected)})")
break
else:
print("Passwords are identical character by character")
else:
print(f"Length mismatch: got {len(db_password)}, expected {len(expected_password)}")
# Test DNS resolution first
print(f"Testing DNS resolution for {db_host}")
try:
socket.gethostbyname(db_host)
print(f"DNS resolution successful for {db_host}")
except socket.gaierror as e:
print(f"DNS resolution failed for {db_host}: {e}")
print("Skipping migrations due to DNS error.")
return
execute_from_command_line(['manage.py', 'migrate'])
print("Migrations completed successfully!")
except Exception as e:
print(f"Migration error: {e}")
# Continue anyway to avoid blocking the server
# Run migrations when this module is imported
if __name__ != '__main__':
run_migrations()