From 104f97fb2e4775cf4225803446b174031a404132 Mon Sep 17 00:00:00 2001 From: Maik Hoepfel Date: Thu, 7 Nov 2013 11:24:03 +0000 Subject: [PATCH] Travis: Fix migrations and ensure failing * Use correct username for MySQL on Travis Travis docs say username should be 'travis', not 'root'. * Fail test_migrations.sh if any command fails Previously, a failing (non-zero exit code) command would not lead to a non-zero exit code of test_migrations.sh. That meant that failing migrations would not fail the Travis job as intended. --- .travis.yml | 3 +++ sites/sandbox/settings_mysql.py | 4 ++-- sites/sandbox/settings_postgres.py | 4 ++-- sites/sandbox/test_migrations.sh | 23 +++++++++++++---------- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4970951c93e..5c28d2bdcef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,9 @@ env: - DJANGO_VERSION=1.5.5 install: - easy_install Django==$DJANGO_VERSION +before_script: + - mysql -e 'create database oscar_vagrant;' + - psql -c 'create database oscar_vagrant;' -U postgres script: - make travis after_success: diff --git a/sites/sandbox/settings_mysql.py b/sites/sandbox/settings_mysql.py index 443ce113c86..a66fbe382e0 100644 --- a/sites/sandbox/settings_mysql.py +++ b/sites/sandbox/settings_mysql.py @@ -4,8 +4,8 @@ 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'oscar_vagrant', - 'USER': 'oscar_user', - 'PASSWORD': 'oscar_password', + 'USER': 'travis', + 'PASSWORD': '', 'HOST': 'localhost', 'PORT': '', } diff --git a/sites/sandbox/settings_postgres.py b/sites/sandbox/settings_postgres.py index ca46586d743..2e02d6b089e 100644 --- a/sites/sandbox/settings_postgres.py +++ b/sites/sandbox/settings_postgres.py @@ -4,8 +4,8 @@ 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'oscar_vagrant', - 'USER': 'oscar_user', - 'PASSWORD': 'oscar_password', + 'USER': 'travis', + 'PASSWORD': '', 'HOST': '127.0.0.1', 'PORT': '', } diff --git a/sites/sandbox/test_migrations.sh b/sites/sandbox/test_migrations.sh index 657053b1056..fde4f5c1e9b 100755 --- a/sites/sandbox/test_migrations.sh +++ b/sites/sandbox/test_migrations.sh @@ -1,22 +1,25 @@ #!/usr/bin/env bash -if [ "$TRAVIS" == "true" ] +# fail if any command fails +# http://stackoverflow.com/questions/90418/exit-shell-script-based-on-process-exit-code +set -e +set -o pipefail + +if [ ! "$TRAVIS" == "true" ] then - ROOT_PASSWORD="" -else - ROOT_PASSWORD="root_password" + mysql -u root --password="root_password" -e "DROP DATABASE IF EXISTS oscar_vagrant; CREATE DATABASE oscar_vagrant" + mysql -u root --password="root_password" -e "GRANT ALL PRIVILEGES ON oscar_vagrant.* TO 'travis'@'%' IDENTIFIED BY '';" + + sudo -u postgres psql -c "DROP ROLE IF EXISTS travis" + sudo -u postgres psql -c "CREATE ROLE travis LOGIN PASSWORD ''" + sudo -u postgres psql -c "DROP DATABASE IF EXISTS oscar_vagrant" + sudo -u postgres psql -c "CREATE DATABASE oscar_vagrant" fi # MySQL -mysql -u root --password=$ROOT_PASSWORD -e "DROP DATABASE IF EXISTS oscar_vagrant; CREATE DATABASE oscar_vagrant" -mysql -u root --password=$ROOT_PASSWORD -e "GRANT ALL PRIVILEGES ON oscar_vagrant.* TO 'oscar_user'@'%' IDENTIFIED BY 'oscar_password';" ./manage.py syncdb --noinput --settings=settings_mysql > /dev/null ./manage.py migrate --noinput --settings=settings_mysql # Postgres -sudo -u postgres psql -c "DROP DATABASE IF EXISTS oscar_vagrant" -sudo -u postgres psql -c "CREATE DATABASE oscar_vagrant" -sudo -u postgres psql -c "DROP ROLE IF EXISTS oscar_user" -sudo -u postgres psql -c "CREATE ROLE oscar_user LOGIN PASSWORD 'oscar_password'" ./manage.py syncdb --noinput --settings=settings_postgres > /dev/null ./manage.py migrate --noinput --settings=settings_postgres \ No newline at end of file