Closed ksclarke closed 6 years ago
The tests do run if RAILS_ENV=test be rake db:setup
is run, like described in Hardy's ticket but that was supposed to not be needed. The database.yml is current (test is supposed to use: database: <%= ENV['DATABASE_NAME'] || 'californica_test' %>
) and the .env.test file has DATABASE_NAME=californica_test
in it.
Going to throw some notes in here as I go since I'm learning.
rake db:create : creates the database from DATABASE_URL or config/database.yml for the
current RAILS_ENV (use db:create:all to create all databases in the config). Without
RAILS_ENV or when RAILS_ENV is development, it defaults to creating the development
and test databases.
rake db:setup : creates the database, loads the schema, and initialises with the seed
data (use db:reset to also drop the database first)
And using be rails c
to view ENV['RAILS_ENV']
in the running VM tells me the environment is set to 'development'.
So I could just use db:create:all
in the provisioning script but that seems to be ignoring what might be a problem. Wondering if the Ansible roles have RAILS_ENV set for "production" since that's their intended use.
From the VM, .env doesn't seem to be being picked up for db:setup. I have to supply DATABASE_USERNAME or else it will use the default 'californica'. Databases are created when using the 'vagrant' user though (like they should be).
vagrant@localhost:~/californica$ DATABASE_USERNAME=vagrant bundle exec rake db:setup
Created database 'californica_development'
Created database 'californica_test'
.env.* files are at /opt/californica/shared/
Going to look at packer output and see if that db:setup runs but fails (without a failed exit code) in the provisioning.
Oh, yes, it tried to create role with the default 'californica' user instead of the user in the .env.* (and when it "failed" it didn't fail the packer build, meaning the command didn't return a non-zero result):
==> box: Provisioning with shell script: scripts/hyrax-dev-config.sh
box: CREATE ROLE
box: fe_sendauth: no password supplied
box: Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>5, "timeout"=>5000, "host"=>"localhost", "min_messages"=>"warning", "username"=>"californica", "password"=>nil, "database"=>"californica_development"}
box: rake aborted!
box: PG::ConnectionBad: fe_sendauth: no password supplied
box: /usr/local/bin/bundle:30:in `block in <main>'
box: /usr/local/bin/bundle:22:in `<main>'
box: Tasks: TOP => db:setup => db:schema:load_if_ruby => db:create
box: (See full trace by running task with --trace)
The build was broken by the PR that changed the databases.
rake ci
now says the database does not exist. We run db:setup as a part of the provisioning but may have now hit the issue Hardy had where the test dbs were not created by the db:setup: https://github.com/UCLALibrary/californica/issues/36