Parcourir la source

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.
master
Maik Hoepfel il y a 11 ans
Parent
révision
e4fd3d7d61

+ 3
- 0
.travis.yml Voir le fichier

@@ -11,6 +11,9 @@ env:
11 11
   - DJANGO_VERSION=1.5.5
12 12
 install:
13 13
 - easy_install Django==$DJANGO_VERSION
14
+before_script:
15
+  - mysql -e 'create database oscar_vagrant;'
16
+  - psql -c 'create database oscar_vagrant;' -U postgres
14 17
 script:
15 18
 - make travis
16 19
 after_success:

+ 2
- 2
sites/sandbox/settings_mysql.py Voir le fichier

@@ -4,8 +4,8 @@ DATABASES = {
4 4
     'default': {
5 5
         'ENGINE': 'django.db.backends.mysql',
6 6
         'NAME': 'oscar_vagrant',
7
-        'USER': 'oscar_user',
8
-        'PASSWORD': 'oscar_password',
7
+        'USER': 'travis',
8
+        'PASSWORD': '',
9 9
         'HOST': 'localhost',
10 10
         'PORT': '',
11 11
     }

+ 2
- 2
sites/sandbox/settings_postgres.py Voir le fichier

@@ -4,8 +4,8 @@ DATABASES = {
4 4
     'default': {
5 5
         'ENGINE': 'django.db.backends.postgresql_psycopg2',
6 6
         'NAME': 'oscar_vagrant',
7
-        'USER': 'oscar_user',
8
-        'PASSWORD': 'oscar_password',
7
+        'USER': 'travis',
8
+        'PASSWORD': '',
9 9
         'HOST': '127.0.0.1',
10 10
         'PORT': '',
11 11
     }

+ 13
- 10
sites/sandbox/test_migrations.sh Voir le fichier

@@ -1,22 +1,25 @@
1 1
 #!/usr/bin/env bash
2 2
 
3
-if [ "$TRAVIS" == "true" ]
3
+# fail if any command fails
4
+# http://stackoverflow.com/questions/90418/exit-shell-script-based-on-process-exit-code
5
+set -e
6
+set -o pipefail
7
+
8
+if [ ! "$TRAVIS" == "true" ]
4 9
 then
5
-  ROOT_PASSWORD=""
6
-else
7
-  ROOT_PASSWORD="root_password"
10
+  mysql -u root --password="root_password" -e "DROP DATABASE IF EXISTS oscar_vagrant; CREATE DATABASE oscar_vagrant"
11
+  mysql -u root --password="root_password" -e "GRANT ALL PRIVILEGES ON oscar_vagrant.* TO 'travis'@'%' IDENTIFIED BY '';"
12
+
13
+  sudo -u postgres psql -c "DROP ROLE IF EXISTS travis"
14
+  sudo -u postgres psql -c "CREATE ROLE travis LOGIN PASSWORD ''"
15
+  sudo -u postgres psql -c "DROP DATABASE IF EXISTS oscar_vagrant"
16
+  sudo -u postgres psql -c "CREATE DATABASE oscar_vagrant"
8 17
 fi
9 18
 
10 19
 # MySQL
11
-mysql -u root --password=$ROOT_PASSWORD -e "DROP DATABASE IF EXISTS oscar_vagrant; CREATE DATABASE oscar_vagrant"
12
-mysql -u root --password=$ROOT_PASSWORD -e "GRANT ALL PRIVILEGES ON oscar_vagrant.* TO 'oscar_user'@'%' IDENTIFIED BY 'oscar_password';"
13 20
 ./manage.py syncdb --noinput --settings=settings_mysql > /dev/null
14 21
 ./manage.py migrate --noinput --settings=settings_mysql
15 22
 
16 23
 # Postgres
17
-sudo -u postgres psql -c "DROP DATABASE IF EXISTS oscar_vagrant"
18
-sudo -u postgres psql -c "CREATE DATABASE oscar_vagrant"
19
-sudo -u postgres psql -c "DROP ROLE IF EXISTS oscar_user"
20
-sudo -u postgres psql -c "CREATE ROLE oscar_user LOGIN PASSWORD 'oscar_password'"
21 24
 ./manage.py syncdb --noinput --settings=settings_postgres > /dev/null
22 25
 ./manage.py migrate --noinput --settings=settings_postgres

Chargement…
Annuler
Enregistrer