Error Dumping Database - Error


#1

Hey All

I am attempting to move to CI 2.0 but I keep getting an error when the DB migrations are complete.

First, I have a Rails 4.2.4 app running on Ruby 2.3.6 and Postgres 9.4.

I am getting the following error after the migrations complete:

Error dumping database
/home/circleci/my_app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.4/lib/active_record/tasks/postgresql_database_tasks.rb:55:in `structure_dump'
/home/circleci/my_app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:182:in `structure_dump'
/home/circleci/my_app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.4/lib/active_record/railties/databases.rake:279:in `block (3 levels) in <top (required)>'
/home/circleci/my_app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.4/lib/active_record/railties/databases.rake:53:in `block (2 levels) in <top (required)>'
/home/circleci/my_app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.4/lib/active_record/railties/databases.rake:45:in `block (2 levels) in <top (required)>'
/usr/local/bundle/bin/bundle:104:in `load'
/usr/local/bundle/bin/bundle:104:in `<main>'
Tasks: TOP => db:structure:dump
(See full trace by running task with --trace)
Exited with code 1

Below is my config file:

version: 2.0

jobs:
  checkout_code:
    working_directory: ~/my_app
    docker:
      - image: circleci/ruby:2.3.6-node
        environment:
          PGHOST: 127.0.0.1
          PGUSER: my_app_user
      - image: circleci/postgres:9.4-alpine
        environment:
          POSTGRES_USER: my_app_user
          POSTGRES_DB: my_app
          POSTGRES_PASSWORD: ""
    steps:
      - checkout
      - save_cache:
          key: v1-repo-{{ .Environment.CIRCLE_SHA1 }}
          paths:
            - ~/my_app

  bundle_dependencies:
    docker:
      - image: circleci/ruby:2.3.6-node
        environment:
          PGHOST: 127.0.0.1
          PGUSER: my_app_user
      - image: circleci/postgres:9.4-alpine
        environment:
          POSTGRES_USER: my_app_user
          POSTGRES_DB: my_app
          POSTGRES_PASSWORD: ""
    working_directory: ~/my_app
    steps:
      - restore_cache:
          keys:
            - v1-repo-{{ .Environment.CIRCLE_SHA1 }}
      - restore_cache:
          keys:
            - v1-bundle-{{ checksum "Gemfile.lock" }}
      - run:
          name: Install System Dependencies
          command: |
            sudo apt-get install qt5-default libqt5webkit5-dev gstreamer1.0-plugins-base gstreamer1.0-tools gstreamer1.0-x
            sudo apt-get install postgresql-client
      - run:
          name: Install Tests Dependencies
          command: |
            bundle install --jobs=2 --retry=3 --path vendor/bundle
      - run: bundle install --path vendor/bundle
      - save_cache:
          key: v1-bundle-{{ checksum "Gemfile.lock" }}
          paths:
            - ~/my_app/vendor/bundle

  rake_test:
    docker:
      - image: circleci/ruby:2.3.6-node
        environment:
          PGHOST: 127.0.0.1
          PGUSER: my_app_user
      - image: circleci/postgres:9.4-alpine
        environment:
          POSTGRES_USER: my_app_user
          POSTGRES_DB: my_app
          POSTGRES_PASSWORD: ""
    working_directory: ~/my_app
    steps:
      - restore_cache:
          keys:
            - v1-repo-{{ .Environment.CIRCLE_SHA1 }}
      - restore_cache:
          keys:
            - v1-bundle-{{ checksum "Gemfile.lock" }}
      - run: bundle --path vendor/bundle
      - run: bundle exec rake db:create; bundle exec rake db:migrate; bundle exec rake db:migrate RAILS_ENV=test
      - run: bundle exec rake sunspot:solr:start --trace

      - run:
          name: Run tests
          command: bundle exec rake

  precompile_assets:
    docker:
      - image: circleci/ruby:2.3.6-node
        environment:
          PGHOST: 127.0.0.1
          PGUSER: my_app_user
      - image: circleci/postgres:9.4-alpine
        environment:
          POSTGRES_USER: my_app_user
          POSTGRES_DB: my_app
          POSTGRES_PASSWORD: ""
    working_directory: ~/my_app
    steps:
      - restore_cache:
          keys:
            - v1-repo-{{ .Environment.CIRCLE_SHA1 }}
      - restore_cache:
          keys:
            - v1-bundle-{{ checksum "Gemfile.lock" }}
      - run: bundle --path vendor/bundle
      - run:
          name: Precompile assets
          command: bundle exec rake assets:precompile
      - save_cache:
          key: v1-assets-{{ .Environment.CIRCLE_SHA1 }}
          paths:
            - ~/my_app/public/assets

workflows:
  version: 2
  build-and-deploy:
    jobs:
      - checkout_code
      - bundle_dependencies:
          requires:
            - checkout_code
      - rake_test:
          requires:
            - bundle_dependencies
      - precompile_assets:
          requires:
            - bundle_dependencies

I should say that I am not entirely sure why it appears that I need to run the migrations in the test environment. Isn’t that something that should be taken care of by my structure.sql/schema.rb file? However, I get a pending migrations error if I omit running the migrations even though there are no pending migrations.

So, my question is two-fold: do I really need to run the migrations in the test environment (I didn’t in CI 1.0), and if so, can someone tell me what I am doing wrong or missing that my database dump fails?

I appreciate the help.

Thnx


#2

There isn’t much in CI in general that would cause this, and my approach is generally to work out why a particular error happens in general. I assume from the secondary error that running migrations is required, even if you don’t have any to run, so I would search for the primary error - there is sure to be something on Stack Overflow.

If it helps, run the failing build with the SSH option, and then you’ll have a playpen to SSH into, where you can run and re-run commands as much as required. Just remember this feature eats your build minutes until you exit SSH and cancel the build in the UI, so don’t hang about!


#3

Thanks for replying halfer. However, I am just not sure why I would even need to run a migration when I am leading the schema in a new DB. I am wondering if there is perhaps something amiss in my config file. Anything jumps out at you?
Again, thanks for your help.

H


#4

Not a Rails/Ruby person, so I’d be stuck. As I say, treat the problem(s) as if CI was not involved - how would a Ruby dev investigate these problems on a local machine?


#5

halfer,

The tests run successfully locally. I am convinced my problem is related to my configuration of dependencies.

H


#6

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