Skip to content

Commit

Permalink
back: Enhance model generation script with output directory and logging.
Browse files Browse the repository at this point in the history
- Introduced OUTPUT_DIR variable for specifying output directory for generated
  models.
- Added directory existence check and creation for OUTPUT_DIR.
- Redirected sequelize-auto output to a log file for better tracking.
- Added success and error message logging for model generation.

Signed-off-by: Nikolay Martyanov <ohmspectator@gmail.com>
  • Loading branch information
OhmSpectator committed Oct 5, 2023
1 parent b0783b7 commit b4c8ecc
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion backend/scripts/generate-models.sh
Original file line number Diff line number Diff line change
@@ -9,6 +9,13 @@ fi
# Load environment variables
source .env

OUTPUT_DIR='./src/models/generated'

# Check if output directory exists, if not create it
if [ ! -d "$OUTPUT_DIR" ]; then
mkdir -p "$OUTPUT_DIR"
fi

# Check the required environment variables
REQUIRED_VARIABLES=(DB_NAME DB_USER DB_PASSWORD)
for VARIABLE in "${REQUIRED_VARIABLES[@]}"; do
@@ -18,4 +25,11 @@ for VARIABLE in "${REQUIRED_VARIABLES[@]}"; do
fi
done

sequelize-auto -o './src/models' -d "$DB_NAME" -h localhost -u "$DB_USER" -x "$DB_PASSWORD" -p 5432 -e postgres --schema gadm
sequelize-auto -o $OUTPUT_DIR -d "$DB_NAME" -h localhost -u "$DB_USER" -x "$DB_PASSWORD" -p 5432 -e postgres --schema gadm > generate-models.log

if [ $? -eq 0 ]; then
echo "Models generated successfully"
rm generate-models.log
else
echo "Error generating models"
fi

0 comments on commit b4c8ecc

Please sign in to comment.