CircleCI 2.0 with more than 1 database in a Rails app


#1

I have an app that requires 2 databases. The first one gets created without issue, via db:create and db:schema:load

The second database is not being created. The rake task is run, but the code for the rake task is:
system(mysql -uubuntu -e "create database test")

It appears it is trying to run this on the base local image, which is not what I want. I tried adding -h 127.0.0.1 to the command, but then it claims it cannot connect to the host.

Config file looks like this:

version: 2
jobs:
  build:
    docker:
      - image: tenshotanaka/ruby-and-node
        env:
          - RAILS_ENV=test
      - image: circleci/mysql:5.7.18
        env:
          - MYSQL_ALLOW_EMPTY_PASSWORD=true
          - MYSQL_USER=ubuntu
          - MYSQL_ROOT_HOST=%

    steps:
      - checkout

      - run:
          name: install node dependencies
          command: npm install

      - run:
          name: install Ruby dependencies
          command: |
            gem install bundler
            bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3

      - run:
          name: setup Finder database
          command: bundle exec rake db:create db:schema:load --trace

      - run:
          name: Run node tests
          command: npm test

      - run:
          name: Run Rake tests
          command: rake test
          environment:
            DATABASE_URL: mysql2://127.0.0.1:3306

#2

Try removing those env vars and using the root user. We already define them:


#3

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.