-
Notifications
You must be signed in to change notification settings - Fork 3
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
a00b601
commit ac1ff7a
Showing
5 changed files
with
51 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
REINDEX DATABASE api; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
ANALYZE; |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/sh | ||
|
||
# Directory where SQL scripts are stored | ||
SQL_DIR="./scripts/reindex_and_stats" | ||
|
||
# Export the database password for psql command | ||
export PGPASSWORD="$DATABASE_PASSWORD" | ||
|
||
# Check if directory exists | ||
if [ ! -d "$SQL_DIR" ]; then | ||
echo "Directory $SQL_DIR does not exist." | ||
exit 1 | ||
fi | ||
|
||
# Find all SQL files in the directory, sort them numerically, and loop through each one | ||
for sql_file in $(ls $SQL_DIR/*.sql | sort -V); do | ||
echo "Running $sql_file ..." | ||
|
||
# Create a temporary file for the modified SQL | ||
temp_file=$(mktemp) | ||
|
||
# Check if password is empty and exit if it is! | ||
if [ -z "$CUSTOM_SQL_DATABASE_PASSWORD" ]; then | ||
echo "CUSTOM_SQL_DATABASE_PASSWORD is empty. Exiting..." | ||
exit 1 | ||
fi | ||
|
||
# Run the modified SQL file | ||
psql -h "$DATABASE_HOSTNAME" -U "$DATABASE_USERNAME" -d "$DATABASE_NAME" -p "$DATABASE_PORT" -f "$temp_file" | ||
|
||
# Check for errors | ||
if [ $? -ne 0 ]; then | ||
echo "Error occurred while executing $sql_file. Exiting." | ||
rm "$temp_file" # Remove the temp file if an error occurs | ||
exit 1 | ||
fi | ||
|
||
# Remove the temporary file after successful execution | ||
rm "$temp_file" | ||
done | ||
|
||
echo "All scripts executed successfully." | ||
|
||
# Unset the password environment variable | ||
unset PGPASSWORD |
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