-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-postgres.sh
More file actions
76 lines (61 loc) · 1.96 KB
/
setup-postgres.sh
File metadata and controls
76 lines (61 loc) · 1.96 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
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
# PostgreSQL Setup Script for File Upload Application
# This script helps set up PostgreSQL for the file upload backend
echo "========================================="
echo "PostgreSQL Setup for File Upload App"
echo "========================================="
echo ""
# Check if PostgreSQL is installed
if ! command -v psql &> /dev/null; then
echo "❌ PostgreSQL is not installed!"
echo ""
echo "Please install PostgreSQL first:"
echo " - Windows: https://www.postgresql.org/download/windows/"
echo " - Mac: brew install postgresql@14"
echo " - Linux: sudo apt-get install postgresql postgresql-contrib"
exit 1
fi
echo "✅ PostgreSQL is installed"
echo ""
# Get database credentials
read -p "PostgreSQL username [postgres]: " DB_USER
DB_USER=${DB_USER:-postgres}
read -sp "PostgreSQL password: " DB_PASSWORD
echo ""
read -p "Database name [fileupload]: " DB_NAME
DB_NAME=${DB_NAME:-fileupload}
read -p "Database host [localhost]: " DB_HOST
DB_HOST=${DB_HOST:-localhost}
read -p "Database port [5432]: " DB_PORT
DB_PORT=${DB_PORT:-5432}
echo ""
echo "Creating database '$DB_NAME'..."
# Create database
PGPASSWORD=$DB_PASSWORD psql -U $DB_USER -h $DB_HOST -p $DB_PORT -c "CREATE DATABASE $DB_NAME;" 2>/dev/null
if [ $? -eq 0 ]; then
echo "✅ Database created successfully"
else
echo "⚠️ Database might already exist or there was an error"
fi
echo ""
echo "Creating .env file..."
# Create .env file
cat > backend/.env << EOF
# PostgreSQL Database Configuration
DB_HOST=$DB_HOST
DB_PORT=$DB_PORT
DB_NAME=$DB_NAME
DB_USER=$DB_USER
DB_PASSWORD=$DB_PASSWORD
EOF
echo "✅ .env file created at backend/.env"
echo ""
echo "========================================="
echo "Setup Complete!"
echo "========================================="
echo ""
echo "Next steps:"
echo "1. Install dependencies: npm install"
echo "2. Start the backend: npm run dev:backend"
echo ""
echo "The database tables will be created automatically on first run."