database configuration does not specify adapter when preparing asset precompile - ruby-on-rails

I recently switched my test database to be postgrsql from sqlite3. Since doing so, when I follow the instruction here: https://devcenter.heroku.com/articles/rails-asset-pipeline on deploying my assets to heroku, I get the following error:
database configuration does not specify adapter
This happens after running this step
RAILS_ENV=production bundle exec rake assets:precompile
I tried following the instructions from this post and it did not work.
bundle exec rake assets:precompile - database configuration does not specify adapter
I'm guessing it has something to do with my database.yml file, which is here
development:
adapter: postgresql
database: playerpong_database
pool: 5
timeout: 5000
encoding: unicode
host: localhost
Any ideas?

I figured it out. I added a production section to my database.yml file.
production:
adapter: postgresql
database: playerpong_database
pool: 5
timeout: 5000
encoding: unicode
host: my_app_url
I didn't think this was needed.

Just pass a dummy database as mentioned in this article:
https://iprog.com/posting/2013/07/errors-when-precompiling-assets-in-rails-4-0
The command is: bundle exec rake RAILS_ENV=production DATABASE_URL=postgresql://user:pass#127.0.0.1/dbname assets:precompile

The problem is you are running
RAILS_ENV=production bundle exec rake assets:precompile
where as your file has development adapter , and so the error comes to be like the adapter is missing.
You need to either change the environment article to development
RAILS_ENV=development bundle exec rake assets:precompile
or change the development directive to production
production:
adapter: postgresql
database: playerpong_database
pool: 5
timeout: 5000
encoding: unicode
host: localhost

Related

$development_db_name$ does not exist error even after running db:create and db:migrate and getting report that they exist

So I seemingly successfully installed postgres for production for heroku deployment, but locally rails seems to not find/nor create the database.
When I go to localhost:3000 I get the error:
ActiveRecord::NoDatabaseError
FATAL: database "dimension_development" does not exist Run `$ bin/rake db:create db:migrate` to create your database
When I run $bin/rake db:create I get:
~ already exists
Then, run db:migrate and restart the rails server, reload the page, and get same error.
So I tried instead to run $bin/rake db:create:all and got:
~ already exists
dimension_test already exists
dimension_production already exists
Then did db:migrate again but nothing changed.
If they already exist, why isn't rails finding them? I notice that in the config/db folder there is still the old development.sqlite3 file but no postgres file.
Any idea what could be going on to cause this error?
My database.yml is:
development:
adapter: postgresql
database: dimension_development
pool: 5
timeout: 5000
test:
adapter: postgresql
database: dimension_test
pool: 5
timeout: 5000
production:
adapter: postgresql
database: dimension_production
pool: 5
timeout: 5000
Thanks! This has got me stumped and I haven't been able to find anything on stackoverflow dealing with this pitfall.
In case of postgresql you will not find any file like development.sqlite3. It's in case of sqlite only.
You did not provided database credential in your database.yml file might causing this error. Try pass username and password as well.
development:
adapter: postgresql
database: dimension_development
pool: 5
timeout: 5000
username: xxxx
password: xxxx

bundle exec rake db:migrate hangs on Amazon EC2 and RDS

I have an EC2 instance (m3.medium) that runs my Rails application and connected to an RDS instance for the MySQL database.
When running 'bundle exec rake db:migrate', the process hangs indefinitely without outputting any error. Any ideas on how to debug this?
Edit the database.yml as:-
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: database_name
pool: 5
username: username
password: password
host: abcdef.amazonaws.com
Run the migration as:-
bundle exec rake RAILS_ENV=production db:migrate

ActiveRecord::AdapterNotSpecified: 'postgresql' database is not configured

I trying to figure out how fix the active record problem so I can push to heroku.
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
ActiveRecord::AdapterNotSpecified: 'postgresql' database is not configured. Available: ["development", "adapter", "encoding",
"database", "host", "pool", "username", "password", "production"]
development:
adapter: postgresql
encoding: unicode
database: sample_app_development
host: localhost
pool: 5
username: sample_app
password:
test:
adapter: postgresql
encoding: unicode
database: sample_app_test
host: localhost
pool: 5
username: sample_app
password:
production:
adapter: postgresql
encoding: unicode
database: sample_app_production
host: localhost
pool: 5
username: sample_app
password:
There is a space before development in the db config. I believe To fix it, simply remove space from the first line and follow the indentation.
I think you need to write this command on terminal to create you database:
rake db:create
Then run rake db:migrate to run your migrations
Remove spaces on 1st line " development:"
Make sure of the database name e.g. "sample_app_development" or just "sample_app"
gem install pg
rake db:create
rake db:migrate
First install postgresql
gem install pg
Then create project using following command:
rails new myapp -d postgresql

rake db:test:clone RAILS_ENV="test" fails, Odd Error: database configuration does not specify adapter

I am running rake db:test:clone RAILS_ENV="test" and I get the error: database configuration does not specify adapter.
My database.yml is as follows:
development:
adapter: postgresql
encoding: unicode
host: localhost
database: mydb_development
username: mydbuser
password:
allow_concurrency: true
pool: 5
min_messages: warning
test:
adapter: postgresql
encoding: unicode
host: localhost
database: mydb_test
username: mydbuser
password:
pool: 5
ps. rake db:test:prepare RAILS_ENV="test" returns the same error.
On "test" I am not sure if host is required. I deleted it and tried again just in case. Any ideas?
Update
When I execute rake db:create:all I get a notice:
mydb_development already exists
Isn't it suppose to also return mydb_test already exists?
I run bundle exec rake db:create RAILS_ENV=test and got the same error.
try to set environment variable before the actual command
RAILS_ENV="test" rake db:test:clone
As per our IRC conversation!
rake db:drop
rake db:create
RAILS_ENV=test rake db:create
RAILS_ENV=test rake db:migrate

Rails with Octopus gem. How to create db's defined in shards.yml with rake

I need to configure my app to use multiple shards, and even multiple db adapters. I have noticed that all rake commands like rake db:migrate are working, and have consequence on shards defined in shards.yml, except rake db:create.
It will be a real pain to create all this manually.
How can I make it work?
My database.yml (I have defined here, only my master shard)
development:
adapter: postgresql
host: localhost
encoding: unicode
database: db_workload_master_development
pool: 5
username:
password:
production:
......
My shards.yml
octopus:
environments:
- production
- development
development:
shards:
mysql:
host: localhost
adapter: mysql2
database: db_workload_mysql_shard_development
sqlite:
host: localhost
adapter: sqlite3
database: db_workload_sqlite_shard_development
pg:
host: localhost
adapter: postgresql
database: db_workload_pg_shard_development
pool: 5
username:
password:
production:
....
Only db's from database.yml are created with rake-task rake db:create.
I would recommend creating your own rake task that will read the shards.yml and create the db's as appropriate.
I think the Octopus gem using shards rake task like db
Try rake shards:create

Resources