If .migration_info values are missing, prompt user for them (#637)

This commit is contained in:
Ryder Wishart 2023-07-13 09:57:50 -07:00 committed by GitHub
parent fc76f9d466
commit 76d409fbec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,17 +6,29 @@ run_sql_file() {
PGPASSWORD=${DB_PASSWORD} psql -h "${DB_HOST}" -p "${DB_PORT}" -d "${DB_NAME}" -U "${DB_USER}" -f "$file"
}
# Check if .migration_info exists and source it, otherwise ask user for inputs
# Flag to indicate whether to prompt for DB info
prompt_for_db_info=false
# Check if .migration_info exists and source it
if [ -f .migration_info ]; then
source .migration_info
# Check if any of the variables are empty
if [ -z "$DB_HOST" ] || [ -z "$DB_NAME" ] || [ -z "$DB_PORT" ] || [ -z "$DB_USER" ] || [ -z "$DB_PASSWORD" ]; then
prompt_for_db_info=true # Some values are empty, so prompt user for values
fi
else
prompt_for_db_info=true # No .migration_info file, so prompt user for values
fi
# If .migration_info doesn't exist or any of the variables are empty, prompt for DB info
if $prompt_for_db_info ; then
echo "Please enter the following database connection information that can be found in Supabase in Settings -> database:"
DB_HOST=$(gum input --placeholder "Host")
DB_NAME=$(gum input --placeholder "Database name")
DB_PORT=$(gum input --placeholder "Port")
DB_USER=$(gum input --placeholder "User")
DB_PASSWORD=$(gum input --placeholder "Password" --password)
# Save the inputs in .migration_info file
echo "DB_HOST=$DB_HOST" > .migration_info
echo "DB_NAME=$DB_NAME" >> .migration_info