Back

Travis-CI: Running `php artisan migrate --no-interaction -vvv` displays no output, no log files created.


Hello!

I'm running across an issue where none of the php artisan migrate commands give any output when validating the commit using Travis CI.

My travis.yml file:

language: php
php:
  - 5.6
  - 5.5
  - 5.4

env:
  - DB=mysql

before_script:
  - mv example.env.php .env.testing.php
  - travis_retry composer self-update
  - travis_retry composer install --prefer-source --no-interaction --dev
  - chmod -R 777 app/storage
  - chmod +x .travis_create_db.sh; ./.travis_create_db.sh
  - php artisan migrate:install --no-interaction -vvv

script: 
  - phpunit --verbose
  - php artisan migrate --no-interaction -vvv
  - php artisan migrate:rollback --no-interaction -vvv

after_script:
  - ls -laR app/storage
  - cat app/storage/logs/*

notifications:
  email:
    - [email protected]
  irc:
    channels:
      - "irc.freenode.net##zarthus"
    template:
      - "%{repository}#%{build_number} (%{branch} - %{commit}) %{author}: %{message} - %{build_url}"
  on_failure: always
  on_success: change

Shell script for creating the database user:

#!/bin/bash

echo "DB=$DB"

if [[ "$DB" == "mysql" ]]; then
  mysql --execute "CREATE DATABASE IF NOT EXISTS \`it-ao-alfa\`;" --user=root
  mysql --execute "USE \`it-ao-alfa\`;" --user=root
  mysql --execute "CREATE USER 'it-ao-alfa'@'localhost';" --user=root
  mysql --execute "GRANT ALL PRIVILEGES ON \`it-ao-alfa\`.* TO 'it-ao-alfa'@'localhost';" --user=root
  mysql --execute "FLUSH PRIVILEGES;" --user=root
fi

Example Tests: https://travis-ci.org/Zarthus/University-of-Potential-Happiness/jobs/44025937

Where travis delivers the following output:

0.15s $ php artisan migrate --no-interaction -vvv
The command "php artisan migrate --no-interaction -vvv" exited with 0.
0.15s $ php artisan migrate:rollback --no-interaction -vvv
The command "php artisan migrate:rollback --no-interaction -vvv" exited with 0.

Regardless of what I even attempt, there is no output shown. No error logs are created, there are definitely migrations, and it just doesn't appear to be working. I have tried everything I could think of, but I fear I am at a loss. Locally everything works, I have tried building it from the ground up with a new vps and it just works. Could there be an issue with Travis, or is my configuration for the testing environment wrong? am I not making the databases correctly with the shell script? I have no idea.

Which is where I was hoping that the people of the internet could help find out what is wrong, or give me some suggestions on how to accurately troubleshoot this issue.

Thanks for looking into this issue, and if you have any suggestions, do let me know!

pagnificence replied 2 years ago

I use MySQL and migrations in Travis without any issues.

MySQL on Travis binds to 127.0.0.1 and using 'localhost' doesn't work.

You're using .env.testing.php, but you're not telling artisan that it's running in that environment - try adding --env=testing to all the artisan calls.

No need to create a db user, just use root with an empty password.

I wouldn't bother with a shell script personally, just use mysql -e in before_script to create the db.

Here is my known working .travis.yml file - very similar to yours - maybe it'll help:

language: php
php:
 - 5.6
 - 5.5

before_script:
 - mv travis.env.php .env.testing.php
 - mysql -e 'create database defdx;'
 - composer self-update
 - composer install --dev --prefer-source --no-interaction
 - chmod -R 777 app/storage
 - php artisan migrate:install --env=testing --no-interaction -vvv

script:
 - php artisan migrate --env=testing --no-interaction -vvv
 - php artisan db:seed --env=testing --no-interaction -vvv
 - vendor/bin/codecept run functional
 - php artisan migrate:rollback --env=testing --no-interaction -vvv

matrix:
 fast_finish: true

My travis.env.php file:

<?php
return [
    'DB_HOST'         => '127.0.0.1',
    'DB_NAME'         => 'defdx',
    'DB_USER'         => 'root',
    'DB_PASS'         => ''
];

And the mysql config in the connections array in database.php:

		'mysql' => array(
			'driver'    => 'mysql',
			'host'      => getenv('DB_HOST'),
			'database'  => getenv('DB_NAME'),
			'username'  => getenv('DB_USER'),
			'password'  => getenv('DB_PASS'),
			'charset'   => 'utf8',
			'collation' => 'utf8_unicode_ci',
			'prefix'    => '',
		)


Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us