-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.sh
executable file
·43 lines (35 loc) · 897 Bytes
/
database.sh
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
#!/bin/bash
# Checks if PostgreSQL service is running
check_postgres_service() {
pg_isready > /dev/null 2>&1
}
# Starts PostgreSQL service
start_postgres_service() {
sudo service postgresql start
}
# Creates the chess database if it doesn't exist
create_database() {
psql -c "CREATE DATABASE IF NOT EXISTS chess;"
}
# Creates the users table if it doesn't exist
create_table() {
psql -d chess -c "
CREATE TABLE IF NOT EXISTS users (
id SERIAL PRIMARY KEY,
username VARCHAR(255),
password VARCHAR(255)
);
"
}
# Check if PostgreSQL service is running
if ! check_postgres_service; then
echo "PostgreSQL service is not running. Starting the service..."
start_postgres_service
fi
# Create the chess database
echo "Creating 'chess' database..."
create_database
# Create the users table
echo "Creating 'users' table..."
create_table
echo "Setup complete."