-
-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathvalidate_db.py
More file actions
48 lines (41 loc) · 1.44 KB
/
validate_db.py
File metadata and controls
48 lines (41 loc) · 1.44 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
#!/usr/bin/env python3
"""
Simple wrapper for database validation that reads from environment variables
"""
import os
import sys
import subprocess
import psycopg
def main():
# Get database config from environment variables (same as the app uses)
db_type = os.environ.get('DB_TYPE', 'postgresql')
db_host = os.environ.get('DB_HOST', 'localhost')
db_port = os.environ.get('DB_PORT', '5432' if db_type == 'postgresql' else '3306')
db_user = os.environ.get('DB_USER', 'postgres' if db_type == 'postgresql' else 'root')
db_password = os.environ.get('DB_PASSWORD', '')
db_name = os.environ.get('DB_NAME', 'pinepods_database')
if not db_password:
print("Error: DB_PASSWORD environment variable is required")
sys.exit(1)
# Build command
cmd = [
sys.executable,
'database_functions/validate_database.py',
'--db-type', db_type,
'--db-host', db_host,
'--db-port', db_port,
'--db-user', db_user,
'--db-password', db_password,
'--db-name', db_name
]
# Add verbose flag if requested
if '--verbose' in sys.argv or '-v' in sys.argv:
cmd.append('--verbose')
print(f"Validating {db_type} database: {db_user}@{db_host}:{db_port}/{db_name}")
print("Running database validation...")
print()
# Run the validator
result = subprocess.run(cmd)
sys.exit(result.returncode)
if __name__ == '__main__':
main()