lundi 5 mars 2018

Error during Heroku CI setup with in-dyno database(Rails & Postgresql)

I'm kinda new to Ruby on Rails. I've been trying to setup Heroku CI, in order to run automated tests before deployment. The plan is simple: deploy a change to GitHib and run some tests against test db data, and if everything is fine push to Heroku. Here is what I added to my app.json file:

    "environments": {
        "test": {
            "addons": ["heroku-postgresql:in-dyno"],
            "scripts": {
               "test": "bundle exec rake test"
            }
         }
     }

The tests run on my dev machine, but "Test setup" fails in Heroku CI, when it runs "rake db:schema:load_if_ruby". I get the following error:

     rake aborted!
     ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  
     relation <userTableName> does not exist
     LINE 5:                WHERE a.attrelid = 
     <userTableName>::regclass......

I tried to override "rake db:schema:load_if_ruby", by replacing it with another task:

    Rake::TaskManager.class_eval do
       def delete_task(task_name)
          if task_name =='db:schema:load_if_ruby'
              Rake::Task["db:test:load"].invoke
          end
       end
    end

But then I get the following error:

    -----> Detecting rake tasks
         sh: 2: Syntax error: Unterminated quoted string
    !
    !     Could not detect rake tasks
    !     ensure you can run `$ bundle exec rake -P` against your app
    !     and using the production group of your Gemfile.
    !     ** Invoke db:test:load (first_time)
    !     ** Invoke db:test:purge (first_time)
    !     ** Execute db:test:purge
    !     ** Execute db:test:load
    !     ** Invoke db:test:load_schema (first_time)
    !     ** Invoke db:test:purge
    !     ** Execute db:test:load_schema
    !     rake aborted!
    !     ActiveRecord::ConnectionNotEstablished: ActiveRecord::ConnectionNotEstablished

Looks like the test db didn't get setup. What should I do to get the test db running and to connect to it? Any help is much appreciated!

Aucun commentaire:

Enregistrer un commentaire