-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4cc945c
commit 941cf99
Showing
4 changed files
with
40 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,31 @@ | ||
#!/bin/bash | ||
|
||
echo "Attente de PostgreSQL avant de procéder à l'importation..." | ||
# Démarre PostgreSQL si ce n'est pas déjà fait | ||
echo "Starting PostgreSQL..." | ||
pg_ctl -D /var/lib/postgresql/data -l /var/log/postgresql.log start & | ||
|
||
# Attend que PostgreSQL soit prêt | ||
echo "Waiting for PostgreSQL before proceeding with the import..." | ||
until pg_isready -U postgres; do | ||
echo "Attente de PostgreSQL..." | ||
echo "Waiting for PostgreSQL..." | ||
sleep 2 | ||
done | ||
|
||
psql -U postgres -d postgres -c "DROP DATABASE IF EXISTS \"wild-transfer\";" | ||
psql -U postgres -d postgres -c "CREATE DATABASE \"wild-transfer\";" | ||
# Check if the database already exists | ||
DB_EXIST=$(psql -U postgres -tAc "SELECT 1 FROM pg_database WHERE datname='wild-transfer'") | ||
|
||
if [ "$DB_EXIST" != "1" ]; then | ||
echo "The database 'wild-transfer' does not exist, creating it..." | ||
psql -U postgres -d postgres -c "CREATE DATABASE \"wild-transfer\";" | ||
|
||
LATEST_DUMP=$(ls -t '/dumps' | head -n 1) | ||
if [ -z "$LATEST_DUMP" ]; then | ||
echo "Aucun fichier dump trouvé dans '/dumps'" | ||
exit 1 | ||
# Restore the dump only if the database has just been created | ||
LATEST_DUMP=$(ls -t '/dumps' | head -n 1) | ||
if [ -z "$LATEST_DUMP" ]; then | ||
echo "No dump file found in '/dumps'. The database remains empty." | ||
else | ||
echo "Restoring dump file $LATEST_DUMP into the 'wild-transfer' database..." | ||
psql -U postgres -d "wild-transfer" < "/dumps/$LATEST_DUMP" | ||
fi | ||
else | ||
echo "Restaurer le fichier dump $LATEST_DUMP dans la base de données 'wild-transfer'" | ||
psql -U postgres -d "wild-transfer" < "/dumps/$LATEST_DUMP" | ||
echo "The database 'wild-transfer' already exists. No changes made." | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
CREATE DATABASE "wild-transfer" NOT EXISTS | ||
CREATE DATABASE "wild-transfer" |