-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup2.sh
More file actions
executable file
·51 lines (41 loc) · 1.13 KB
/
Copy pathsetup2.sh
File metadata and controls
executable file
·51 lines (41 loc) · 1.13 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
#!/bin/bash
# Set your PostgreSQL connection details as environment variables
export PGHOST="localhost"
export PGPORT="5432"
export PGDATABASE="crud_rest"
export PGUSER="komil"
export PGPASSWORD="komil008I"
# Function to check if Node.js dependencies are installed
dependencies_installed() {
[ -d "node_modules" ]
}
# Function to check if a database exists
database_exists() {
psql -lqt | cut -d \| -f 1 | grep -qw $PGDATABASE
}
# Function to check if tables exist in the database
tables_exist() {
psql -d $PGDATABASE -c '\dt' | grep -qw 'users\|posts'
}
# Check if Node.js dependencies are installed
if ! dependencies_installed; then
# Install Node.js dependencies
npm install
fi
# Create database if it doesn't exist
if ! database_exists; then
createdb
fi
# Connect to database and execute SQL script if tables don't exist
if ! tables_exist; then
psql -f "database.sql"
fi
# Run your Node.js application
npm run dev
# Function to delete PostgreSQL database
delete_database() {
echo "Deleting PostgreSQL database..."
dropdb
}
# Uncomment the line below to delete the database after running the application
# delete_database