From 033b529c17aa06736cdf4dc43fd201b2957249ac Mon Sep 17 00:00:00 2001 From: Nicholas Ellul Date: Wed, 10 May 2023 14:45:19 -0400 Subject: [PATCH] Fix script to build migrations by having it use the `.ts` template (#18878) * Fix script to build migrations * Validate version is a number --- development/generate-migration.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/development/generate-migration.sh b/development/generate-migration.sh index 0e08b9421..791563e3e 100755 --- a/development/generate-migration.sh +++ b/development/generate-migration.sh @@ -1,12 +1,24 @@ #! /bin/bash + +validate-number(){ + re='^[0-9]+$' + if [[ ! $1 =~ $re ]]; then + echo "Error: The value must be a number." >&2 + exit 1 + fi +} + g-migration() { [[ -z "$1" ]] && { echo "Migration version is required!" ; exit 1; } local vnum=$1 + + validate-number "$vnum" + if (($1 < 100)); then vnum=0$1 fi - touch app/scripts/migrations/"$vnum".js - cp app/scripts/migrations/template.js app/scripts/migrations/"$vnum".js + touch app/scripts/migrations/"$vnum".ts + cp app/scripts/migrations/template.ts app/scripts/migrations/"$vnum".ts touch app/scripts/migrations/"$vnum".test.js cp app/scripts/migrations/template.test.js app/scripts/migrations/"$vnum".test.js