diff --git a/config/database.yml.default b/config/database.yml.default deleted file mode 100644 index c3a2fa2c..00000000 --- a/config/database.yml.default +++ /dev/null @@ -1,27 +0,0 @@ -# SQLite version 3.x -# gem install sqlite3 -development: - adapter: postgresql - encoding: unicode - database: nztrain - pool: 5 - username: www-data - password: - -# Warning: The database defined as "test" will be erased and -# re-generated from your development database when you run "rake". -# Do not set this db to the same as development or production. -test: - adapter: postgresql - encoding: unicode - database: nztraintest - pool: 5 - username: postgres - -production: - adapter: postgresql - encoding: unicode - database: nztrain - pool: 5 - username: www-data - password: diff --git a/config/database.yml.template b/config/database.yml.template index 252b43f7..79d8d6e1 100644 --- a/config/database.yml.template +++ b/config/database.yml.template @@ -1,5 +1,3 @@ -# SQLite version 3.x -# gem install sqlite3 development: adapter: postgresql encoding: unicode diff --git a/script/install/postgresql.bash b/script/install/postgresql.bash index e3358b5a..27f65195 100644 --- a/script/install/postgresql.bash +++ b/script/install/postgresql.bash @@ -4,37 +4,33 @@ cd `dirname $0`/../.. source script/install.cfg -min_version=8 - -psql --version 2>/dev/null | bash script/extract_version.bash | bash script/check_version.bash $min_version || { - echo PostgreSQL $min_version+ required! - bash script/confirm.bash 'Install PostgreSQL' && { - cmd="sudo apt-get install postgresql" - echo "$ $cmd" - $cmd - } || exit 1 - -} - -# required by pg gem +# header files (required by pg gem) cmd="sudo apt-get install libpq-dev" echo "$ $cmd" $cmd || exit 1 -# setup user if required -psql -U$DATABASE_USERNAME postgres -c '' &> /dev/null || { - bash script/confirm.bash "Create new PostgreSQL user $DATABASE_USERNAME" && { - cmd="sudo -u postgres createuser --superuser $DATABASE_USERNAME" - echo "$ $cmd" - $cmd - } || exit 1 +# client utilities (psql, createdb, pg_dump, etc.) +command -v psql >/dev/null || { + cmd="sudo apt-get install postgresql-client" + echo "$ $cmd" + $cmd || exit 1 } -# setup database if required -if [[ $DATABASE ]] ; then - psql -U$DATABASE_USERNAME $DATABASE -c '' &> /dev/null || { - bash script/confirm.bash "Create new PostgreSQL database $DATABASE" && { - cmd="sudo -u postgres createdb $DATABASE" +if [ "${DATABASE_INSTALL:-true}" = "true" ]; then + # install server (not required if the server is running on another host/container) + id -u postgres &> /dev/null || { + echo "PostgreSQL server required!" + bash script/confirm.bash 'Install PostgreSQL server' && { + cmd="sudo apt-get install postgresql" + echo "$ $cmd" + $cmd + } || exit 1 + } + + # setup user if required + psql -U "$DATABASE_USERNAME" postgres -c '' &> /dev/null || { + bash script/confirm.bash "Create new PostgreSQL user $DATABASE_USERNAME" && { + cmd="sudo -u postgres createuser --superuser $DATABASE_USERNAME" echo "$ $cmd" $cmd } || exit 1 @@ -42,13 +38,24 @@ if [[ $DATABASE ]] ; then fi # setup database if required +if [[ $DATABASE ]] ; then + psql -U "$DATABASE_USERNAME" "$DATABASE" -c '' &> /dev/null || { + bash script/confirm.bash "Create new PostgreSQL database $DATABASE" && { + cmd=(createdb -U "$DATABASE_USERNAME" "$DATABASE") + echo "$ ${cmd[@]}" + "${cmd[@]}" + } || exit 1 + } +fi + +# setup test database if required if [[ $TEST_DATABASE ]] ; then - psql -U$DATABASE_USERNAME $TEST_DATABASE -c '' &> /dev/null || { + psql -U "$DATABASE_USERNAME" "$TEST_DATABASE" -c '' &> /dev/null || { bash script/confirm.bash "Create new PostgreSQL database $TEST_DATABASE" && { - cmd="sudo -u postgres createdb $TEST_DATABASE" - echo "$ $cmd" - $cmd - } || exit + cmd=(createdb -U "$DATABASE_USERNAME" "$TEST_DATABASE") + echo "$ ${cmd[@]}" + "${cmd[@]}" + } || exit 1 } fi