How to set up Travis Rspec for testing read replicas accessed in a Rails application Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experience Should we burninate the [wrap] tag?How do you run a single test/spec file in RSpec?How to run a single RSpec test?rails 3.1.3: rake aborts (couldn't parse YAML) when run first db:migrate (trying to run postgres locally on mac lion)postgres 'psql' command is not recognized in windows environmentRails 4.0.4, ruby 2.1.0, Ubuntu 12.04 rake db:create fails, postgresql making me sadIssue in setting up a Ruby On Rails project on another machinerails console hangs in production environmentRails Postgres database setup on Travis CITravis CI: start cypress on rails serverSending email on travis

What is the musical term for a note that continously plays through a melody?

Examples of mediopassive verb constructions

How discoverable are IPv6 addresses and AAAA names by potential attackers?

If a contract sometimes uses the wrong name, is it still valid?

Should I use Javascript Classes or Apex Classes in Lightning Web Components?

When -s is used with third person singular. What's its use in this context?

What makes black pepper strong or mild?

Antler Helmet: Can it work?

"Seemed to had" is it correct?

Is the Standard Deduction better than Itemized when both are the same amount?

How does cp -a work

Why does Python start at index 1 when iterating an array backwards?

How to deal with a team lead who never gives me credit?

What is a Meta algorithm?

3 doors, three guards, one stone

Did Kevin spill real chili?

I am not a queen, who am I?

How do I stop a creek from eroding my steep embankment?

Why is "Consequences inflicted." not a sentence?

Does polymorph use a PC’s CR or its level?

Output the ŋarâþ crîþ alphabet song without using (m)any letters

Check which numbers satisfy the condition [A*B*C = A! + B! + C!]

What do you call a plan that's an alternative plan in case your initial plan fails?

What are the pros and cons of Aerospike nosecones?



How to set up Travis Rspec for testing read replicas accessed in a Rails application



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experience
Should we burninate the [wrap] tag?How do you run a single test/spec file in RSpec?How to run a single RSpec test?rails 3.1.3: rake aborts (couldn't parse YAML) when run first db:migrate (trying to run postgres locally on mac lion)postgres 'psql' command is not recognized in windows environmentRails 4.0.4, ruby 2.1.0, Ubuntu 12.04 rake db:create fails, postgresql making me sadIssue in setting up a Ruby On Rails project on another machinerails console hangs in production environmentRails Postgres database setup on Travis CITravis CI: start cypress on rails serverSending email on travis



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have a rails application that accesses two databases: a read replica and it's own database configured through a standard database.yml file.



There are certain models that access the read replica, and I use establish_connection to dynamically switch over to the replica:



class MyReadReplicaDbBase < ActiveRecord::Base
self.abstract_class = true
establish_connection READ_REPLICA_DB
end

class User < MyReadReplicaDbBase
end


Actual environments work well with this setup, but while testing on travis, I need to set up two databases using an approach like this:



language: ruby

cache: bundler

rvm:
- 2.5.1

services:
- docker
- redis-server

env:
global:
- DB_URL=postgres://postgres@localhost/travis_ci_test
- READ_REPLICA_DB_URL=postgres://postgres@localhost/travis_ci_read_replica_test


# https://github.com/travis-ci/travis-ci/issues/9624#issuecomment-389537036
before_install:
- sudo sed -i -e '/local.*peer/s/postgres/all/' -e 's/peer|md5/trust/g' /etc/postgresql/*/main/pg_hba.conf
- sudo service postgresql restart
- sleep 1
- gem update --system
- gem install bundler

sudo: required
dist: xenial
addons:
postgresql: "10"
apt:
packages:
- postgresql-10
- postgresql-client-10
env:
global:
- PGPORT=5433

before_script:
- cp config/database.yml.travis config/database.yml
- psql -c 'create database travis_ci_test;' -U postgres
- psql -c 'create database travis_ci_read_replica_test' -U postgres


script:
- bundle exec rails db:migrate RAILS_ENV=test
- bundle exec rspec -f d



Is there a standard approach to load the schema in the replica database for testing? Can I run something like the following?



rake:db:schema:load --database read_replica_db


I understand this won't work because it will pull the default environment to set up that database.










share|improve this question



















  • 1





    "Setup": noun. "Set up": verb phrase.

    – sawa
    Mar 22 at 8:11

















0















I have a rails application that accesses two databases: a read replica and it's own database configured through a standard database.yml file.



There are certain models that access the read replica, and I use establish_connection to dynamically switch over to the replica:



class MyReadReplicaDbBase < ActiveRecord::Base
self.abstract_class = true
establish_connection READ_REPLICA_DB
end

class User < MyReadReplicaDbBase
end


Actual environments work well with this setup, but while testing on travis, I need to set up two databases using an approach like this:



language: ruby

cache: bundler

rvm:
- 2.5.1

services:
- docker
- redis-server

env:
global:
- DB_URL=postgres://postgres@localhost/travis_ci_test
- READ_REPLICA_DB_URL=postgres://postgres@localhost/travis_ci_read_replica_test


# https://github.com/travis-ci/travis-ci/issues/9624#issuecomment-389537036
before_install:
- sudo sed -i -e '/local.*peer/s/postgres/all/' -e 's/peer|md5/trust/g' /etc/postgresql/*/main/pg_hba.conf
- sudo service postgresql restart
- sleep 1
- gem update --system
- gem install bundler

sudo: required
dist: xenial
addons:
postgresql: "10"
apt:
packages:
- postgresql-10
- postgresql-client-10
env:
global:
- PGPORT=5433

before_script:
- cp config/database.yml.travis config/database.yml
- psql -c 'create database travis_ci_test;' -U postgres
- psql -c 'create database travis_ci_read_replica_test' -U postgres


script:
- bundle exec rails db:migrate RAILS_ENV=test
- bundle exec rspec -f d



Is there a standard approach to load the schema in the replica database for testing? Can I run something like the following?



rake:db:schema:load --database read_replica_db


I understand this won't work because it will pull the default environment to set up that database.










share|improve this question



















  • 1





    "Setup": noun. "Set up": verb phrase.

    – sawa
    Mar 22 at 8:11













0












0








0








I have a rails application that accesses two databases: a read replica and it's own database configured through a standard database.yml file.



There are certain models that access the read replica, and I use establish_connection to dynamically switch over to the replica:



class MyReadReplicaDbBase < ActiveRecord::Base
self.abstract_class = true
establish_connection READ_REPLICA_DB
end

class User < MyReadReplicaDbBase
end


Actual environments work well with this setup, but while testing on travis, I need to set up two databases using an approach like this:



language: ruby

cache: bundler

rvm:
- 2.5.1

services:
- docker
- redis-server

env:
global:
- DB_URL=postgres://postgres@localhost/travis_ci_test
- READ_REPLICA_DB_URL=postgres://postgres@localhost/travis_ci_read_replica_test


# https://github.com/travis-ci/travis-ci/issues/9624#issuecomment-389537036
before_install:
- sudo sed -i -e '/local.*peer/s/postgres/all/' -e 's/peer|md5/trust/g' /etc/postgresql/*/main/pg_hba.conf
- sudo service postgresql restart
- sleep 1
- gem update --system
- gem install bundler

sudo: required
dist: xenial
addons:
postgresql: "10"
apt:
packages:
- postgresql-10
- postgresql-client-10
env:
global:
- PGPORT=5433

before_script:
- cp config/database.yml.travis config/database.yml
- psql -c 'create database travis_ci_test;' -U postgres
- psql -c 'create database travis_ci_read_replica_test' -U postgres


script:
- bundle exec rails db:migrate RAILS_ENV=test
- bundle exec rspec -f d



Is there a standard approach to load the schema in the replica database for testing? Can I run something like the following?



rake:db:schema:load --database read_replica_db


I understand this won't work because it will pull the default environment to set up that database.










share|improve this question
















I have a rails application that accesses two databases: a read replica and it's own database configured through a standard database.yml file.



There are certain models that access the read replica, and I use establish_connection to dynamically switch over to the replica:



class MyReadReplicaDbBase < ActiveRecord::Base
self.abstract_class = true
establish_connection READ_REPLICA_DB
end

class User < MyReadReplicaDbBase
end


Actual environments work well with this setup, but while testing on travis, I need to set up two databases using an approach like this:



language: ruby

cache: bundler

rvm:
- 2.5.1

services:
- docker
- redis-server

env:
global:
- DB_URL=postgres://postgres@localhost/travis_ci_test
- READ_REPLICA_DB_URL=postgres://postgres@localhost/travis_ci_read_replica_test


# https://github.com/travis-ci/travis-ci/issues/9624#issuecomment-389537036
before_install:
- sudo sed -i -e '/local.*peer/s/postgres/all/' -e 's/peer|md5/trust/g' /etc/postgresql/*/main/pg_hba.conf
- sudo service postgresql restart
- sleep 1
- gem update --system
- gem install bundler

sudo: required
dist: xenial
addons:
postgresql: "10"
apt:
packages:
- postgresql-10
- postgresql-client-10
env:
global:
- PGPORT=5433

before_script:
- cp config/database.yml.travis config/database.yml
- psql -c 'create database travis_ci_test;' -U postgres
- psql -c 'create database travis_ci_read_replica_test' -U postgres


script:
- bundle exec rails db:migrate RAILS_ENV=test
- bundle exec rspec -f d



Is there a standard approach to load the schema in the replica database for testing? Can I run something like the following?



rake:db:schema:load --database read_replica_db


I understand this won't work because it will pull the default environment to set up that database.







ruby-on-rails ruby postgresql rspec travis-ci






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 8:07









sawa

133k29208308




133k29208308










asked Mar 22 at 8:05









SidSid

2,76762947




2,76762947







  • 1





    "Setup": noun. "Set up": verb phrase.

    – sawa
    Mar 22 at 8:11












  • 1





    "Setup": noun. "Set up": verb phrase.

    – sawa
    Mar 22 at 8:11







1




1





"Setup": noun. "Set up": verb phrase.

– sawa
Mar 22 at 8:11





"Setup": noun. "Set up": verb phrase.

– sawa
Mar 22 at 8:11












1 Answer
1






active

oldest

votes


















0














So I got it working using a Personal access token and copying the schema over using this script



#load_read_replica_schema.rb
#!/home/travis/.rvm/rubies/ruby-2.5.1/bin/ruby

def install_gems()
system('gem install pg')
system('gem install activerecord -v=5.2.2')
end

def get_read_replica_schema_file
require 'active_record'
require 'active_record/tasks/database_tasks'
require 'active_record/tasks/postgresql_database_tasks'

curl_command = "curl -s https://#ENV['PERSONAL_ACCESS_TOKEN']@raw.githubusercontent.com/<owner>/<repo>/master/db/schema.rb -o read_replica_schema.rb"
system(curl_command)


ActiveRecord::Tasks::DatabaseTasks.load_schema('postgres://postgres:@localhost/travis_ci_read_replica_test', :ruby, 'read_replica_schema.rb', :test)
end


install_gems()
get_read_replica_schema_file()


Similarly updated the script to run on the travis.yaml script with a script



before_script:
- cp config/database.yml.travis config/database.yml
- psql -c 'create database travis_ci_test;' -U postgres
- psql -c 'create database travis_ci_read_replica_test' -U postgres

script:
- ./load_read_replica_api_schema.rb
- bundle exec rails db:migrate RAILS_ENV=test
- bundle exec rspec -f d





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55295272%2fhow-to-set-up-travis-rspec-for-testing-read-replicas-accessed-in-a-rails-applica%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    So I got it working using a Personal access token and copying the schema over using this script



    #load_read_replica_schema.rb
    #!/home/travis/.rvm/rubies/ruby-2.5.1/bin/ruby

    def install_gems()
    system('gem install pg')
    system('gem install activerecord -v=5.2.2')
    end

    def get_read_replica_schema_file
    require 'active_record'
    require 'active_record/tasks/database_tasks'
    require 'active_record/tasks/postgresql_database_tasks'

    curl_command = "curl -s https://#ENV['PERSONAL_ACCESS_TOKEN']@raw.githubusercontent.com/<owner>/<repo>/master/db/schema.rb -o read_replica_schema.rb"
    system(curl_command)


    ActiveRecord::Tasks::DatabaseTasks.load_schema('postgres://postgres:@localhost/travis_ci_read_replica_test', :ruby, 'read_replica_schema.rb', :test)
    end


    install_gems()
    get_read_replica_schema_file()


    Similarly updated the script to run on the travis.yaml script with a script



    before_script:
    - cp config/database.yml.travis config/database.yml
    - psql -c 'create database travis_ci_test;' -U postgres
    - psql -c 'create database travis_ci_read_replica_test' -U postgres

    script:
    - ./load_read_replica_api_schema.rb
    - bundle exec rails db:migrate RAILS_ENV=test
    - bundle exec rspec -f d





    share|improve this answer



























      0














      So I got it working using a Personal access token and copying the schema over using this script



      #load_read_replica_schema.rb
      #!/home/travis/.rvm/rubies/ruby-2.5.1/bin/ruby

      def install_gems()
      system('gem install pg')
      system('gem install activerecord -v=5.2.2')
      end

      def get_read_replica_schema_file
      require 'active_record'
      require 'active_record/tasks/database_tasks'
      require 'active_record/tasks/postgresql_database_tasks'

      curl_command = "curl -s https://#ENV['PERSONAL_ACCESS_TOKEN']@raw.githubusercontent.com/<owner>/<repo>/master/db/schema.rb -o read_replica_schema.rb"
      system(curl_command)


      ActiveRecord::Tasks::DatabaseTasks.load_schema('postgres://postgres:@localhost/travis_ci_read_replica_test', :ruby, 'read_replica_schema.rb', :test)
      end


      install_gems()
      get_read_replica_schema_file()


      Similarly updated the script to run on the travis.yaml script with a script



      before_script:
      - cp config/database.yml.travis config/database.yml
      - psql -c 'create database travis_ci_test;' -U postgres
      - psql -c 'create database travis_ci_read_replica_test' -U postgres

      script:
      - ./load_read_replica_api_schema.rb
      - bundle exec rails db:migrate RAILS_ENV=test
      - bundle exec rspec -f d





      share|improve this answer

























        0












        0








        0







        So I got it working using a Personal access token and copying the schema over using this script



        #load_read_replica_schema.rb
        #!/home/travis/.rvm/rubies/ruby-2.5.1/bin/ruby

        def install_gems()
        system('gem install pg')
        system('gem install activerecord -v=5.2.2')
        end

        def get_read_replica_schema_file
        require 'active_record'
        require 'active_record/tasks/database_tasks'
        require 'active_record/tasks/postgresql_database_tasks'

        curl_command = "curl -s https://#ENV['PERSONAL_ACCESS_TOKEN']@raw.githubusercontent.com/<owner>/<repo>/master/db/schema.rb -o read_replica_schema.rb"
        system(curl_command)


        ActiveRecord::Tasks::DatabaseTasks.load_schema('postgres://postgres:@localhost/travis_ci_read_replica_test', :ruby, 'read_replica_schema.rb', :test)
        end


        install_gems()
        get_read_replica_schema_file()


        Similarly updated the script to run on the travis.yaml script with a script



        before_script:
        - cp config/database.yml.travis config/database.yml
        - psql -c 'create database travis_ci_test;' -U postgres
        - psql -c 'create database travis_ci_read_replica_test' -U postgres

        script:
        - ./load_read_replica_api_schema.rb
        - bundle exec rails db:migrate RAILS_ENV=test
        - bundle exec rspec -f d





        share|improve this answer













        So I got it working using a Personal access token and copying the schema over using this script



        #load_read_replica_schema.rb
        #!/home/travis/.rvm/rubies/ruby-2.5.1/bin/ruby

        def install_gems()
        system('gem install pg')
        system('gem install activerecord -v=5.2.2')
        end

        def get_read_replica_schema_file
        require 'active_record'
        require 'active_record/tasks/database_tasks'
        require 'active_record/tasks/postgresql_database_tasks'

        curl_command = "curl -s https://#ENV['PERSONAL_ACCESS_TOKEN']@raw.githubusercontent.com/<owner>/<repo>/master/db/schema.rb -o read_replica_schema.rb"
        system(curl_command)


        ActiveRecord::Tasks::DatabaseTasks.load_schema('postgres://postgres:@localhost/travis_ci_read_replica_test', :ruby, 'read_replica_schema.rb', :test)
        end


        install_gems()
        get_read_replica_schema_file()


        Similarly updated the script to run on the travis.yaml script with a script



        before_script:
        - cp config/database.yml.travis config/database.yml
        - psql -c 'create database travis_ci_test;' -U postgres
        - psql -c 'create database travis_ci_read_replica_test' -U postgres

        script:
        - ./load_read_replica_api_schema.rb
        - bundle exec rails db:migrate RAILS_ENV=test
        - bundle exec rspec -f d






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 22 at 12:40









        SidSid

        2,76762947




        2,76762947





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55295272%2fhow-to-set-up-travis-rspec-for-testing-read-replicas-accessed-in-a-rails-applica%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript