Our Rails app has just been upgraded to Rails 6.0 but the deployment to Heroku fails with:
Preparing app for Rails asset pipeline
Running: rake assets:precompile
DEPRECATION WARNING: Including LoggerSilence is deprecated and will be removed in Rails 6.1. Please use `ActiveSupport::LoggerSilence` instead (called from <top (required)> at /tmp/build_b9759d496c72c1085bb8441e3c2159fb/config/application.rb:7)
rake aborted!
ActiveRecord::AdapterNotSpecified: database configuration does not specify adapter
/tmp/build_b9759d496c72c1085bb8441e3c2159fb/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.0/lib/active_record/connection_adapters/connection_specification.rb:163:in `spec'
config/database.yml:
default: &default
adapter: postgresql
encoding: utf8
pool: 5
username: <%= ENV['POSTGRESQL_USER'] %>
password:
socket: /tmp/mysql.sock
development:
<<: *default
database: OurApplication_development
test:
<<: *default
database: OurApplication_test
production:
url: <%= ENV['DATABASE_URL'] %>
Using version:
rails (6.0.0)
Ruby (2.6.5)
Does anybody have an idea how to solve this issue?
The problem has been solved by adding the 'adapter' to 'production' in the database.yml. This wasn't necessary when our project was on Rails 4 and 5.
production:
adapter: postgresql
A better solution altogether would just be to use ENV["DATABASE_URL"] to specify the connection details and keep your defaults segment to the actual minimal defaults:
default: &default
adapter: postgresql
encoding: utf8
pool: 5
development:
<<: *default
database: OurApplication_development
test:
<<: *default
database: OurApplication_test
production:
# doing url: is just stupid as thats what rails does anyways
<<: *default
This avoids potential developer wars. You can use DotEnv to load different ENV vars for each environment. Alternatively you can add another hash to to your database.yml and merge it:
default: &default
adapter: postgresql
encoding: utf8
pool: 5
local_settings: &local_settings
# will raise an exception on nil instead of failing silently
username: <%= ENV.fetch('POSTGRESQL_USER') %>
password:
socket: /tmp/mysql.sock
development:
<<: *default
<<: *local_settings
database: OurApplication_development
test:
<<: *default
<<: *local_settings
database: OurApplication_test
production:
# doing url: is just stupid as thats what rails does anyways
<<: *default
I am new to rails, don't know how to access multiple databases in rails single application.
I will try like this
config/database.yml
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: root
password: root
socket: /var/run/mysqld/mysqld.sock
reconnect: true
development:
<<: *default
database: connection_development
<<: *default
database: connection_test
second database
log_database_production:
adapter: mysql2
encoding: utf8
pool: 5
host: 192.168.100.97
port: 3306 #ip address of server with other postgres database
username: root
password: root
database: hrms_development
reconnect: true
then i don't know how to proceed..
I am currently trying to complete a tutorial on ruby on rails and have had this error within IRB when I enter "subject = Subject.new"
Mysql2::Error: Access denied for user 'simple_cms'#'localhost' (using password: YES)
is there a way to supply this to irb when i run
rails console
What is the best way to resolve this?
database.yml is below:
default: &default
adapter: mysql2
encoding: utf8
reconnect: false
host: localhost
pool: 5
username: simple_cms
password: mypasshere
socket: /tmp/mysql.sock
development:
<<: *default
database: simple_cms_development
<<: *default
database: simple_cms_test
production:
<<: *default
database: simple_cms_production
username: simple_cms
password: <%= ENV['SIMPLE_CMS_DATABASE_PASSWORD'] %>
Much appreciated for any help!
I changed my database.yml file to use postgresql instead of sqlite3.
But when I do rake db:migrate - development.sqlite3 file gets created.
Here's my database.yml file:
default: &default
adapter: postgresql
encoding: unicode
pool: 5
host: localhost
development:
<<: *default
database: scrumban_development
test:
<<: *default
database: scrumban_test
production:
<<: *default
database: scrumban_production
username: scrumban
password: <%= ENV['scrumban_DATABASE_PASSWORD'] %>
Don't include the sqlite3 gem and it should stop creating it.
Rails new app.
The current database.yml is like that:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
I need to edit this for postgresql database.
How can I do this?
Simply:
development:
adapter: postgresql
encoding: unicode
database: blog_development
pool: 5
username: blog
password:
host: localhost
Source: Configuring Rails Applications
development:
adapter: postgresql
encoding: utf8
database: name
username: hading
password: my_db_password
pool: 5 # not mandatory
timeout: 5000 # not mandatory
host: localhost
port: your postgresql port number (5432 or 5433)
As Zabba said it's
development:
adapter: postgresql
encoding: unicode
database: blog_development
pool: 5
username: blog
password:
As mentioned in the Configuring Rails Applications. But you might want an additional min_messages: WARNING, to get rid of the nasty NOTICE messages postgresql gives you during a migration. So my database.yml entry looks like this
development:
adapter: postgresql
encoding: unicode
database: blog_development
pool: 5
username: blog
password:
min_messages: WARNING
You might be interested in generating new app with postgres default:
rails new myapp --database=postgresql
as mentioned here: https://devcenter.heroku.com/articles/getting-started-with-rails4
development:
adapter: postgresql
encoding: utf8
database: name
username: hading
password: my_db_password
host: localhost # not mandatory
pool: 5 # not mandatory
timeout: 5000 # not mandatory
Simply use
rails new app_name --database=postgresql
or if existing application try
development:
adapter: postgresql
encoding: unicode
database: app_dev
pool: 5
username: username
password: password
host: localhost
Another way is to have the common values in &default and then have individual values for the other environments, which can be based on environment variables:
default: &default
adapter: postgresql
encoding: unicode
port: <%= ENV.fetch("POSTGRESQL_PORT", "5432") %>
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: <%= ENV['POSTGRESQL_USER_NAME'] %>
password: <%= ENV.fetch("POSTGRESQL_PASSWORD", "myS3cr3tP4ssw0rd") %>
host: <%= ENV['POSTGRESQL_HOST'] %>
development:
<<: *default
database: <%= ENV['POSTGRESQL_DB'] %>-development
host: db
test:
<<: *default
database: <%= ENV['POSTGRESQL_DB'] %>-test
host: db
production:
<<: *default
database: <%= ENV['POSTGRESQL_DB'] %>
Here all the values can come from environment variables (if you use Docker or Bitbucket Pipelines) or you can have them in your .env files.