Skip to content

Commit

Permalink
Travis: Fix migrations and ensure failing
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
maiksprenger committed Nov 7, 2013
1 parent 75ef01a commit 104f97f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions sites/sandbox/settings_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': '',
}
Expand Down
4 changes: 2 additions & 2 deletions sites/sandbox/settings_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': '',
}
Expand Down
23 changes: 13 additions & 10 deletions sites/sandbox/test_migrations.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 104f97f

Please sign in to comment.