From 581d8718272b96b4906fd3b5564de891f0b49418 Mon Sep 17 00:00:00 2001 From: Matt Amos Date: Sat, 8 Mar 2014 11:33:52 +0000 Subject: [PATCH 1/1] Migrate the database on `vagrant up`. Also fix the provisioning script so that it runs correctly when the VM is upped, regardless of whether it's a clean install or an 'up' of a previously halted VM. --- script/vagrant/setup/provision.sh | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/script/vagrant/setup/provision.sh b/script/vagrant/setup/provision.sh index 21d5daf59..f9ba3c98b 100644 --- a/script/vagrant/setup/provision.sh +++ b/script/vagrant/setup/provision.sh @@ -35,13 +35,27 @@ pushd /srv/openstreetmap-website # do bundle install as a convenience sudo -u vagrant -H bundle install # create user and database for openstreetmap-website -sudo -u postgres createuser -s vagrant -sudo -u vagrant -H createdb -E UTF-8 -O vagrant openstreetmap -sudo -u vagrant -H createdb -E UTF-8 -O vagrant osm_test -# add btree_gist extension -sudo -u vagrant -H psql -c "create extension btree_gist" openstreetmap -# TODO: build and set up postgres extensions +db_user_exists=`sudo -u postgres psql postgres -tAc "select 1 from pg_roles where rolname='vagrant'"` +if [ "$db_user_exists" != "1" ]; then + sudo -u postgres createuser -s vagrant + sudo -u vagrant -H createdb -E UTF-8 -O vagrant openstreetmap + sudo -u vagrant -H createdb -E UTF-8 -O vagrant osm_test + # add btree_gist extension + sudo -u vagrant -H psql -c "create extension btree_gist" openstreetmap +fi +# build and set up postgres extensions +pushd db/functions +sudo -u vagrant make +sudo -u vagrant psql openstreetmap -c "drop function if exists maptile_for_point(int8, int8, int4)" +sudo -u vagrant psql openstreetmap -c "CREATE FUNCTION maptile_for_point(int8, int8, int4) RETURNS int4 AS '/srv/openstreetmap-website/db/functions/libpgosm.so', 'maptile_for_point' LANGUAGE C STRICT" +popd # set up sample configs -sudo -u vagrant cp config/example.database.yml config/database.yml -sudo -u vagrant cp config/example.application.yml config/application.yml +if [ ! -f config/database.yml ]; then + sudo -u vagrant cp config/example.database.yml config/database.yml +fi +if [ ! -f config/application.yml ]; then + sudo -u vagrant cp config/example.application.yml config/application.yml +fi +# migrate the database to the latest version +sudo -u vagrant rake db:migrate popd -- 2.39.5