=== modified file 'zsh-functions/confz_postgresql_init' --- zsh-functions/confz_postgresql_init 2014-06-27 17:48:18 +0000 +++ zsh-functions/confz_postgresql_init 2014-06-27 11:02:28 +0000 @@ -65,71 +65,3 @@ data_dir="/var/lib/postgresql/$vars[slot]/data" \ initdb="/usr/lib/postgresql-$vars[slot]/bin/initdb" } - -confz_postgresql_db_check() { - checkvars db owner - defvar user postgres - defvar psql psql - defvar createdb createdb - - local out name owner encoding rest - local -a opts - - opts+=( -U $vars[user] ) - (($+vars[host])) && opts+=( --host=$vars[host] ) - (($+vars[port])) && opts+=( --port=$vars[port] ) - - do_command=( $createdb $opts $db -O $owner ) - if (($+vars[encoding])); then - do_command+=( -E $vars[encoding] ) - fi - - out=$( $psql $opts -lAP tuples_only=on ) || die "psql failed" - while IFS='|' read name owner encoding rest; do - if [[ $name == $vars[db] ]]; then - [[ $owner == $vars[owner] ]] || \ - die "database $name has owner $owner, want $vars[owner]" - if (($+vars[encoding])); then - [[ $encoding == $vars[encoding] ]] || \ - die "database $name has encoding $encoding, want $vars[encoding]" - fi - return 0 - fi - done - - fail_reason="database ${(qqq)vars[name]} was not found" - return 1 -} - -confz_postgresql_schema_check() { - checkvars db schema psql_input - defvar user postgres - defvar psql psql - - local out - local -a opts - - opts+=( -U $vars[user] ) - (($+vars[host])) && opts+=( --host=$vars[host] ) - (($+vars[port])) && opts+=( --port=$vars[port] ) - - out=$( $psql $opts -AP tuples_only=on -c '\d' $vars[db] ) || die "psql failed" - if [[ -z $out ]]; then - fail_reason="the schema for ${(qqq)db} is empty" - return 1 - elif [[ $out != $schema ]]; then - die "the schema for ${(qqq)db} differs:"$'\n'$( \ - diff -u <(print -r - $schema) <(print -r - $out) ) - fi - return 0 -} - -confz_postgresql_schema_do() { - local -a opts - - opts+=( -U $vars[user] ) - (($+vars[host])) && opts+=( --host=$vars[host] ) - (($+vars[port])) && opts+=( --port=$vars[port] ) - - $psql $opts -1 $vars[db] -f - <<<$vars[psql_input] -}