github.com/arkadijs/deis@v1.5.1/contrib/util/_controller-reset-db.sh (about)

     1  #!/usr/bin/env bash -e
     2  
     3  # This code is kept in a separate file from `reste-db.sh` for no other reason than to not have to deal
     4  # with the nightmare of double escaping all these commands through `vagrant ssh -c "\\\\\\\\\AGH!"`
     5  
     6  # NB. Command for exporting fixtures
     7  # `./manage.py dumpdata --natural --indent=4 -e sessions -e admin -e contenttypes -e auth.Permission -e south > /app/deis/api/fixtures/dev.json`
     8  
     9  if [[ $EUID -ne 0 ]]; then
    10     echo "This script must be run as root" 1>&2
    11     exit 1
    12  fi
    13  
    14  if [[ -z "$VP_HOST" && -z "$VP_USER" ]]; then
    15  	echo "VP_HOST and VP_USER must be set"
    16  	exit 1
    17  fi
    18  
    19  cd /vagrant/contrib/vagrant/util
    20  
    21  echo "Dropping and recreating Deis database..."
    22  echo "su postgres -c 'dropdb deis && createdb --encoding=utf8 --template=template0 deis'" | ./dshell deis-database
    23  
    24  echo "Running South migrations..."
    25  echo '/app/manage.py syncdb --migrate --noinput' | ./dshell deis-controller
    26  
    27  echo "Importing fixtures"
    28  echo '/app/manage.py loaddata /app/api/fixtures/dev.json' | ./dshell deis-controller
    29  
    30  # Most of the fixture data is generic. However the host machine's SSH credentials will change
    31  # from developer to developer.
    32  echo "Updating vagrant provider details"
    33  cat <<EOF | ./dshell deis-database
    34  su postgres
    35  psql deis -c "UPDATE api_provider SET creds = '{\"host\": \"$VP_HOST\", \"user\": \"$VP_USER\"}' WHERE owner_id = 1 AND type = 'vagrant' "
    36  EOF