-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_db.sh
More file actions
executable file
·46 lines (40 loc) · 1.12 KB
/
setup_db.sh
File metadata and controls
executable file
·46 lines (40 loc) · 1.12 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
#!/bin/bash
# PostgreSQL connection details
DB_NAME="smartresume"
DB_USER="postgres"
DB_PASSWORD="" # Change this if your PostgreSQL setup requires a password
# Check if psql is available
if ! command -v psql &> /dev/null; then
echo "PostgreSQL client (psql) is not installed. Please install PostgreSQL first."
exit 1
fi
# Check if the database already exists
if psql -lqt | cut -d \| -f 1 | grep -qw "$DB_NAME"; then
echo "Database $DB_NAME already exists"
else
# Create database
if [ -z "$DB_PASSWORD" ]; then
createdb "$DB_NAME"
else
PGPASSWORD="$DB_PASSWORD" createdb -U "$DB_USER" "$DB_NAME"
fi
if [ $? -eq 0 ]; then
echo "Database $DB_NAME created successfully"
else
echo "Failed to create database $DB_NAME"
exit 1
fi
fi
# Update Django settings with database credentials
cat > backend/.env << EOL
DEBUG=True
SECRET_KEY=your-secret-key-here
DB_NAME=$DB_NAME
DB_USER=$DB_USER
DB_PASSWORD=$DB_PASSWORD
DB_HOST=localhost
DB_PORT=5432
ALLOWED_HOSTS=localhost,127.0.0.1
CORS_ORIGIN_WHITELIST=http://localhost:8080
EOL
echo "Database configuration complete!"