Reputation: 1844
I have a sinatra app and i want to configure my development, test and production databases with a database.yaml
file.
Adding this to my app.rb
file and running rake db:migrate
works just fine:
configure :development do
set :database, "sqlite3:forum-service.sqlite3"
end
But i want to keep database configurations separated in a database.yaml
file to keep a cleaner code. If i remove the code above and add the config/database.yaml
file, as shown below, and run rake db:migrate
i get:
rake aborted!
ActiveRecord::ConnectionNotEstablished: No connection pool with 'primary' found.
my config/database.yaml file
development:
adapter: sqlite3
database: db/forum_dev_sqlite3.db
pool: 5
timeout: 5000
test:
adapter: sqlite3
database: db/forum_test_sqlite3.db
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/forum_prod_sqlite3.db
pool: 5
timeout: 5000
my Rakefile
require 'sinatra'
require 'sinatra/activerecord'
require 'sinatra/activerecord/rake'
require './app'
require 'rake/testtask'
task :default do
puts 'type \'rake --tasks\' to list options.'
end
Rake::TestTask.new do |t|
#t.pattern = "tests/**.rb"
t.libs << "test"
t.test_files = FileList['tests/unittest.rb'] # test*.rb for all
t.verbose = true
end
according to Sinatra docs sinatra/databases/postgresql-activerecord by making a config/database.yaml
file the configurations gets automatically loaded but looks like theres something missing to make the connection possible. Maybe add something to my rakefile to read the configs?
I've seen Sinatra, Puma, ActiveRecord: No connection pool with 'primary' found and Sinatra - ActiveRecord::ConnectionNotEstablished: No connection pool for ActiveRecord::Base but they do not apply for this problem.
Upvotes: 0
Views: 1239
Reputation: 10014
sinatra-activerecord looks in config/database.yml (not yaml) by default. You can change to any other path with the :database_file
configuration option.
set :database_file, 'config/database.yaml'
Upvotes: 1