Skip to content

Commit

Permalink
More detailed messages for config migrate.
Browse files Browse the repository at this point in the history
Provide better messages for the `config migrate` subcommand.
  • Loading branch information
fluca1978 committed Nov 18, 2021
1 parent 7f0f760 commit e011310
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,8 @@ location of configuration files into the `config` subdirectory.
```
pgenv config migrate
Migrated 3 configuration files from previous versions (0 missing)
Your configuration files are now into [~/git/misc/PostgreSQL/pgenv/config]
Migrated 3 configuration file(s) from previous versions (0 not migrated)
Your configuration file(s) are now into [~/git/misc/PostgreSQL/pgenv/config]
```
Expand Down
20 changes: 13 additions & 7 deletions bin/pgenv
Original file line number Diff line number Diff line change
Expand Up @@ -1459,25 +1459,31 @@ EOF
mkdir "$PGENV_CONFIG_ROOT"
fi

counter=0
missing=0

files_migrated=0
files_missing=0
files_to_migrate=0
for old_config_file in "$PGENV_ROOT"/.pgenv.*.conf; do
if [ -f "$old_config_file" ]; then
files_to_migrate=$(( files_to_migrate + 1 ))
new_config_file=$( basename "$old_config_file" | sed 's/\.pgenv\.//' )
new_config_file="$PGENV_CONFIG_ROOT/${new_config_file}"
pgenv_debug "Migrating [$old_config_file] to [$new_config_file]"
mv "$old_config_file" "$new_config_file"
if [ $? -eq 0 ]; then
counter=$(( counter + 1 ))
files_migrated=$(( files_migrated + 1 ))
else
missing=$(( missing + 1 ))
files_missing=$(( files_missing + 1 ))
fi
fi
done

if [ $counter -gt 0 ]; then
echo "Migrated $counter configuration files from previous versions ($missing missing)"
echo "Your configuration files are now into [$PGENV_CONFIG_ROOT]"
if [ $files_to_migrate -eq 0 ]; then
echo "No configuration file to migrate!"
else if [ $files_migrated -gt 0 ]; then
echo "Migrated $files_migrated configuration file(s) from previous versions ($files_missing not migrated)"
echo "Your configuration file(s) are now into [$PGENV_CONFIG_ROOT]"
fi
fi
;;

Expand Down

0 comments on commit e011310

Please sign in to comment.