Skip to content

Commit

Permalink
Implement the config migrate command.
Browse files Browse the repository at this point in the history
This command moves the old configuration files (if any) into the
`config` subdirectory.
See <#51 (comment)>
  • Loading branch information
fluca1978 committed Nov 16, 2021
1 parent 1fd149f commit 2f72df7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ The `config` command accepts the following subcommands:
- `edit` opens the current or specified version configuration file in your favourite text editor
(Using `$EDITOR`, e.g: `export EDITOR=/usr/bin/emacs`)
- `delete` removes the specified configuration
- `migrate` is a command used to change the configuration format between versions of `pgenv`


Each sub-command accepts a PostgreSQL version number (e.g., `10.5`) or a
Expand Down Expand Up @@ -738,23 +739,20 @@ configuration file, please issue a rename like the following
cp .pgenv.conf .pgenv.default.conf
```
Please note also that, since version `1.2.1` [811ba05], all the configuration files
have been moved into the `config` subdirectory, so to keep them in a single place.
In order to "migrate" your existing configuration, you have to manually
copy all the `.pgenv.*.conf` files into the `config` subdirectory.
The best way to quickly migrate your configuration files to the new
naming scheme, is running a small shell loop as the following one:
The `migrate` command allows `pgenv` to change the configuration format of
the files between different releases. For example, it must be run if
you are upgrading `pgenv` from a version before `1.2.1` [811ba05], that changed the
location of configuration files into the `config` subdirectory.
```
for f in .pgenv.*.conf; do
F=$( echo $f | sed 's/\.pgenv\.//' ); mv $f config/$F;
done
pgenv config migrate
Migrated 3 configuration files from previous versions (0 missing)
Your configuration files are now into [~/git/misc/PostgreSQL/pgenv/config]
```
that has to be run from your `$PGENV_ROOT`, that is from the directory that
contains the `.pgenv.*.conf` files.
### pgenv log
The `log` command provides a dump of the cluster log, if it exists, so that you
Expand Down
32 changes: 32 additions & 0 deletions bin/pgenv
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,38 @@ EOF
configuration_file=$( pgenv_configuration_file_name $v )

case $action in
migrate)
if [ -z "$PGENV_CONFIG_ROOT" ]; then
PGENV_CONFIG_ROOT="$PGENV_ROOT/config"
echo "No configuration directory set, using [$PGENV_CONFIG_ROOT]"
fi

if [ ! -d "$PGENV_CONFIG_ROOT" ]; then
mkdir "$PGENV_CONFIG_ROOT"
fi

counter=0
missing=0
for old_config_file in "$PGENV_ROOT"/.pgenv.*.conf; do
if [ -f "$old_config_file" ]; then
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 ))
else
missing=$(( 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]"
fi
;;

show)
pgenv_configuration_dump_or_exit "$v" "$title" ;;
init)
Expand Down

0 comments on commit 2f72df7

Please sign in to comment.