Rails - switching my rails app DB from sqlite3 to postgresql - ruby-on-rails

I've create a RoR application with default database sqlite3. but the problem is sqlite3 is supported on heroku (deploying my app on cloud).
It's been whole day but i can't be able to connect my rails app to postgresql.
This is the steps I've followed till now to connect my app to postgresql
Replace: gem 'sqlite3', '~> 1.4'
with: gem 'pg'
then: bundle install
successfully install all the gems
after that convert my db to postgresql
conflict config/database.yml
Overwrite D:/New folder/amazon-product/config/database.yml? (enter "h" for help) [Ynaqdhm]
force config/database.yml
gsub Gemfile
gsub Gemfile
in that it's overwrite my existing database.yml file to postgresql
after that when i enter command
rake db:create db:migrate
it giving me the error
rails db:create db:migrate
rake aborted!
Bundler::GemRequireError: There was an error while trying to load the gem 'pg'.
Gem Load Error is: AddDllDirectory failed for C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/x64-mingw32Backtrace for gem load error is:
C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/dll_directory.rb:83:in `add_dll_directory_winapi'
C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/dll_directory.rb:50:in `initialize'
C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/singleton.rb:12:in `new'
C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/singleton.rb:12:in `add_dll_directory'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:15:in `block in <main>'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:26:in `rescue in <main>'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:4:in `<main>'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:100:in `register'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bundler-2.2.33/lib/bundler/runtime.rb:60:in `block (2 levels) in require'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bundler-2.2.33/lib/bundler/runtime.rb:55:in `each'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bundler-2.2.33/lib/bundler/runtime.rb:55:in `block in require'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bundler-2.2.33/lib/bundler/runtime.rb:44:in `each'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bundler-2.2.33/lib/bundler/runtime.rb:44:in `require'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bundler-2.2.33/lib/bundler.rb:175:in `require'
D:/New folder/amazon-product/config/application.rb:7:in `<top (required)>'
D:/New folder/amazon-product/Rakefile:4:in `require_relative'
D:/New folder/amazon-product/Rakefile:4:in `<top (required)>'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/rake_module.rb:29:in `load'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/rake_module.rb:29:in `load_rakefile'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:710:in `raw_load_rakefile'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:104:in `block in load_rakefile'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:103:in `load_rakefile'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:82:in `block in run'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:80:in `run'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
C:/Ruby30-x64/bin/rake:25:in `load'
C:/Ruby30-x64/bin/rake:25:in `<main>'
Bundler Error Backtrace:
D:/New folder/amazon-product/config/application.rb:7:in `<top (required)>'
D:/New folder/amazon-product/Rakefile:4:in `require_relative'
D:/New folder/amazon-product/Rakefile:4:in `<top (required)>'
Caused by:
RubyInstaller::Runtime::DllDirectory::WinApiError: AddDllDirectory failed for C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/x64-mingw32
D:/New folder/amazon-product/config/application.rb:7:in `<top (required)>'
D:/New folder/amazon-product/Rakefile:4:in `require_relative'
D:/New folder/amazon-product/Rakefile:4:in `<top (required)>'
Caused by:
LoadError: 126: The specified module could not be found. - C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg_ext.so
D:/New folder/amazon-product/config/application.rb:7:in `<top (required)>'
D:/New folder/amazon-product/Rakefile:4:in `require_relative'
D:/New folder/amazon-product/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)
my database.yml
# PostgreSQL. Versions 9.3 and up are supported.
#
# Install the pg driver:
# gem install pg
# On macOS with Homebrew:
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On macOS with MacPorts:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
# Choose the win32 build.
# Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: amazon_product_development
# The specified database role being used to connect to postgres.
# To create additional roles in postgres see `$ createuser --help`.
# When left blank, postgres will use the default role. This is
# the same name as the operating system user running Rails.
#username: amazon_product
# The password associated with the postgres role (username).
#password:
# Connect on a TCP socket. Omitted by default since the client uses a
# domain socket that doesn't need configuration. Windows does not have
# domain sockets, so uncomment these lines.
#host: localhost
# The TCP port the server listens on. Defaults to 5432.
# If your server runs on a different port number, change accordingly.
#port: 5432
# Schema search path. The server defaults to $user,public
#schema_search_path: myapp,sharedapp,public
# Minimum log levels, in increasing order:
# debug5, debug4, debug3, debug2, debug1,
# log, notice, warning, error, fatal, and panic
# Defaults to warning.
#min_messages: notice
# 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:
<<: *default
database: amazon_product_test
# As with config/credentials.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password or a full connection URL as an environment
# variable when you boot the app. For example:
#
# DATABASE_URL="postgres://myuser:mypass#localhost/somedatabase"
#
# If the connection URL is provided in the special DATABASE_URL environment
# variable, Rails will automatically merge its configuration values on top of
# the values provided in this file. Alternatively, you can specify a connection
# URL environment variable explicitly:
#
# production:
# url: <%= ENV['MY_APP_DATABASE_URL'] %>
#
# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full overview on how database connection configuration can be specified.
#
production:
<<: *default
database: amazon_product_production
username: amazon_product
password: <%= ENV['AMAZON_PRODUCT_DATABASE_PASSWORD'] %>
I've already installed postgresql also create a new database table called 'details'
hierarchy of pgadmin 4
server --> postgresql 14 --> databases(2) --> postgres, details(which i want to use)

Related

Ruby on Rails: How to work with RDS MySQL instance locally

Environment
Rails version: 6.0.0.rc2
Ruby version: ruby 2.6.3p62 (2019-04-16 revision 67580)
RDS MySql: Ver 8.0.15
Problem
I am trying to connect my RDS MySQL8 instance to my local Ruby on Rails application for testing purposes. My app is working fine with a local version of MySQL8.0.12 with the mysql2 gem.
When I use the RDS DB's details and I run bin/rake db:[anything] VERBOSE=true in the command line, it just hangs without giving ANY information on why it isn't working. Output below.
This is purely to test the db I want to use for a staging environment.
I've connected to the RDS DB from the command line and DBeaver from my local machine, and I've been able to create new tables, so security groups should be ok.
I've used the db connection test script below to ensure that ActiveRecord::Base.connected is true
Connected, initiated, migrated and seeded a local mysql db just in case.
database.yml
#
default: &default
adapter: mysql2
encoding: utf8mb4
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
host: [aws_rds_host_url]
username: <%= ENV.fetch("DB_USERNAME") %>
password: <%= ENV.fetch("DB_PASSWORD") %>
database: db_name
test script found somewhere on stackoverflow (returns "CONNECTED!")
require './config/environment.rb' # Assuming the script is located in the root of the rails app
begin
ActiveRecord::Base.establish_connection # Establishes connection
ActiveRecord::Base.connection # Calls connection object
puts "CONNECTED!" if ActiveRecord::Base.connected?
puts "NOT CONNECTED!" unless ActiveRecord::Base.connected?
rescue StandardError => e
puts e
puts "rescue:: NOT CONNECTED!"
end
Running bin/rake db:create VERBOSE=true || bin/rake db:migrate VERBOSE=true (or anything rake db:) keeps hanging, tried for more than an hour. It does not make any changes to the DB. Stopped with cmd+C it just returns:
bin/rake db:create VERBOSE=true
^CTraceback (most recent call last):
14: from bin/rake:3:in `<main>'
13: from bin/rake:3:in `load'
12: from [home]/[project dir]/bin/spring:16:in `<top (required)>'
11: from [home]/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
10: from [home]/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
9: from [home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `<top (required)>'
8: from [home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `load'
7: from [home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/bin/spring:49:in `<top (required)>'
6: from [home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client.rb:30:in `run'
5: from [home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/command.rb:7:in `call'
4: from [home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/run.rb:35:in `call'
3: from [home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/run.rb:42:in `warm_run'
2: from [home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/run.rb:62:in `run'
1: from [home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/run.rb:117:in `verify_server_version'
[home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/run.rb:117:in `gets': Interrupt

rake db:migrate gives error

I have spent the last week trying to set up the following config:
VPS with clean Centos 7 install.
Ruby on Rails which runs Redmine, all to read out a back-up of the redmine database made with bacula.
Now mind you, I come from a Graphical design/Microsoft/Hardware engineering background and am now currently transitioning so I'm still very unfamiliar with most of the stack used at my current employer as I have only been working there for a couple of weeks.
Setting up the VPS and installing Centos7 is easy enough, I then proceed with installing rbenv/httpd/bundler/rmagick/all the gems and restore the redmine back-up (back-up from the entire install).
Now I want to run a rake db:migrate command (just following the wiki's from redmine and digital ocean) and this happens:
[user#machinename redmine]$ rake db:migrate
rake aborted!
ActiveRecord::AdapterNotSpecified: 'development' database is not configured. Available: ["production"]
/opt/redmine-3.1.0/lib/plugins/acts_as_activity_provider/init.rb:2:in `block in <top (required)>'
/opt/redmine-3.1.0/config/initializers/00-core_plugins.rb:12:in `eval'
/opt/redmine-3.1.0/config/initializers/00-core_plugins.rb:12:in `block in <top (required)>'
/opt/redmine-3.1.0/config/initializers/00-core_plugins.rb:2:in `each'
/opt/redmine-3.1.0/config/initializers/00-core_plugins.rb:2:in `<top (required)>'
/opt/redmine-3.1.0/config/environment.rb:14:in `<top (required)>'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)
[user#machinename redmine]$
If I then inspect lets say 00-core_plugins.rb I can't seem to find what is wrong.
# Loads the core plugins located in lib/plugins
Dir.glob(File.join(Rails.root, "lib/plugins/*")).sort.each do |directory|
if File.directory?(directory)
lib = File.join(directory, "lib")
if File.directory?(lib)
$:.unshift lib
ActiveSupport::Dependencies.autoload_paths += [lib]
end
initializer = File.join(directory, "init.rb")
if File.file?(initializer)
config = RedmineApp::Application.config
eval(File.read(initializer), binding, initializer)
end
end
end
If anyone could offer some help/insight to what it is I am doing wrong it would be greatly appreciated.
A standalone installer which sets up redmine and all dependencies is also good as I actually only have to be able to import the back-up of the DB in to redmine.
Full --trace:
[user#machinename redmine]$ rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
ActiveRecord::AdapterNotSpecified: 'development' database is not configured. Available: ["production"]
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.3/lib/active_record/connection_adapters/connection_specification.rb:248:in `resolve_symbol_connection'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.3/lib/active_record/connection_adapters/connection_specification.rb:211:in `resolve_connection'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.3/lib/active_record/connection_adapters/connection_specification.rb:139:in `resolve'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.3/lib/active_record/connection_adapters/connection_specification.rb:169:in `spec'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.3/lib/active_record/connection_handling.rb:50:in `establish_connection'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.3/lib/active_record/railtie.rb:120:in `block (2 levels) in <class:Railtie>'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/lazy_load_hooks.rb:44:in `each'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.3/lib/active_record/base.rb:315:in `<module:ActiveRecord>'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.3/lib/active_record/base.rb:26:in `<top (required)>'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `require'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `block in require'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:in `load_dependency'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `require'
/opt/redmine-3.1.0/lib/plugins/acts_as_activity_provider/init.rb:2:in `block in <top (required)>'
/opt/redmine-3.1.0/config/initializers/00-core_plugins.rb:12:in `eval'
/opt/redmine-3.1.0/config/initializers/00-core_plugins.rb:12:in `block in <top (required)>'
/opt/redmine-3.1.0/config/initializers/00-core_plugins.rb:2:in `each'
/opt/redmine-3.1.0/config/initializers/00-core_plugins.rb:2:in `<top (required)>'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in `load'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in `block in load'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:in `load_dependency'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in `load'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.3/lib/rails/engine.rb:652:in `block in load_config_initializer'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/notifications.rb:166:in `instrument'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.3/lib/rails/engine.rb:651:in `load_config_initializer'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.3/lib/rails/engine.rb:616:in `block (2 levels) in <class:Engine>'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.3/lib/rails/engine.rb:615:in `each'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.3/lib/rails/engine.rb:615:in `block in <class:Engine>'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.3/lib/rails/initializable.rb:30:in `instance_exec'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.3/lib/rails/initializable.rb:30:in `run'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.3/lib/rails/initializable.rb:55:in `block in run_initializers'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.3/lib/rails/initializable.rb:44:in `each'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.3/lib/rails/initializable.rb:44:in `tsort_each_child'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/tsort.rb:415:in `call'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/tsort.rb:415:in `each_strongly_connected_component_from'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/tsort.rb:347:in `each'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/tsort.rb:347:in `call'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.3/lib/rails/initializable.rb:54:in `run_initializers'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.3/lib/rails/application.rb:352:in `initialize!'
/opt/redmine-3.1.0/config/environment.rb:14:in `<top (required)>'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `require'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `block in require'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:in `load_dependency'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `require'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.3/lib/rails/application.rb:328:in `require_environment!'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.3/lib/rails/application.rb:457:in `block in run_tasks_blocks'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `block in execute'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `each'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `execute'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/task.rb:201:in `block in invoke_prerequisites'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/task.rb:199:in `each'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/task.rb:199:in `invoke_prerequisites'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/task.rb:178:in `block in invoke_with_call_chain'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/task.rb:165:in `invoke'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/application.rb:150:in `invoke_task'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `each'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block in top_level'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/application.rb:115:in `run_with_threads'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/application.rb:100:in `top_level'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/application.rb:78:in `block in run'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/lib/rake/application.rb:75:in `run'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rake-10.4.2/bin/rake:33:in `<top (required)>'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/bin/rake:22:in `load'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/bin/rake:22:in `<main>'
Tasks: TOP => db:migrate => environment
Database.yml:
# Default setup is given for MySQL with ruby1.9.
# Examples for PostgreSQL, SQLite3 and SQL Server can be found at the end.
# Line indentation must be 2 spaces (no tabs).
production:
adapter: mysql2
database: redmine
host: localhost
username: redmine
password: "therightpassword_icheckeditadozentimes"
encoding: utf8
development:
adapter: mysql2
database: redmine
host: localhost
username: redmine
password: "therightpassword_icheckeditadozentimes"
encoding: utf8
# PostgreSQL configuration example
#production:
# adapter: postgresql
# database: redmine
# host: localhost
# username: postgres
# password: "postgres"
# SQLite3 configuration example
#production:
# adapter: sqlite3
# database: db/redmine.sqlite3
# SQL Server configuration example
#production:
# adapter: sqlserver
# database: redmine
# host: localhost
# username: jenkins
# password: jenkins
Configuration.yml
# = Redmine configuration file
#
# Each environment has it's own configuration options. If you are only
# running in production, only the production block needs to be configured.
# Environment specific configuration options override the default ones.
#
# Note that this file needs to be a valid YAML file.
# DO NOT USE TABS! Use 2 spaces instead of tabs for identation.
# default configuration options for all environments
default:
# Outgoing emails configuration
# See the examples below and the Rails guide for more configuration options:
# http://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration
email_delivery:
delivery_method: :smtp
smtp_settings:
enable_starttls_auto: true
#ssl: true
address: smtp.gmail.com
port: "587"
domain: "site.tld"
authentication: :plain
user_name: "ticketing#site.tld"
password: "god our security is atrocious"
# ==== Simple SMTP server at localhost
#
# email_delivery:
# delivery_method: :smtp
# smtp_settings:
# address: "localhost"
# port: 25
#
# ==== SMTP server at example.com using LOGIN authentication and checking HELO for foo.com
#
# email_delivery:
# delivery_method: :smtp
# smtp_settings:
# address: "example.com"
# port: 25
# authentication: :login
# domain: 'foo.com'
# user_name: 'myaccount'
# password: 'password'
#
# ==== SMTP server at example.com using PLAIN authentication
#
# email_delivery:
# delivery_method: :smtp
# smtp_settings:
configuration.yml # address: "example.com"
# port: 25
# authentication: :plain
# domain: 'example.com'
# user_name: 'myaccount'
# password: 'password'
#
# ==== SMTP server at using TLS (GMail)
# This might require some additional configuration. See the guides at:
# http://www.redmine.org/projects/redmine/wiki/EmailConfiguration
#
# email_delivery:
# delivery_method: :smtp
# smtp_settings:
# enable_starttls_auto: true
# address: "smtp.gmail.com"
# port: 587
# domain: "smtp.gmail.com" # 'your.domain.com' for GoogleApps
# authentication: :plain
# user_name: "your_email#gmail.com"
# password: "your_password"
#
# ==== Sendmail command
#
# email_delivery:
# delivery_method: :sendmail
# Absolute path to the directory where attachments are stored.
# The default is the 'files' directory in your Redmine instance.
# Your Redmine instance needs to have write permission on this
# directory.
# Examples:
# attachments_storage_path: /var/redmine/files
# attachments_storage_path: D:/redmine/files
attachments_storage_path:
# Configuration of the autologin cookie.
# autologin_cookie_name: the name of the cookie (default: autologin)
# autologin_cookie_path: the cookie path (default: /)
# autologin_cookie_secure: true sets the cookie secure flag (default: false)
autologin_cookie_name:
autologin_cookie_path:
autologin_cookie_secure:
# Configuration of SCM executable command.
#
# Absolute path (e.g. /usr/local/bin/hg) or command name (e.g. hg.exe, bzr.exe)
# On Windows + CRuby, *.cmd, *.bat (e.g. hg.cmd, bzr.bat) does not work.
#
# On Windows + JRuby 1.6.2, path which contains spaces does not work.
# For example, "C:\Program Files\TortoiseHg\hg.exe".
# If you want to this feature, you need to install to the path which does not contains spaces.
# For example, "C:\TortoiseHg\hg.exe".
#
# Examples:
# scm_subversion_command: svn # (default: svn)
# scm_mercurial_command: C:\Program Files\TortoiseHg\hg.exe # (default: hg)
# scm_git_command: /usr/local/bin/git # (default: git)
# scm_cvs_command: cvs # (default: cvs)
# scm_bazaar_command: bzr.exe # (default: bzr)
# scm_darcs_command: darcs-1.0.9-i386-linux # (default: darcs)
#
scm_subversion_command:
scm_mercurial_command:
scm_git_command:
scm_cvs_command:
scm_bazaar_command:
scm_darcs_command:
# SCM paths validation.
#
# You can configure a regular expression for each SCM that will be used to
# validate the path of new repositories (eg. path entered by users with the
# "Manage repositories" permission and path returned by reposman.rb).
# The regexp will be wrapped with \A \z, so it must match the whole path.
# And the regexp is case sensitive.
#
# You can match the project identifier by using %project% in the regexp.
#
# You can also set a custom hint message for each SCM that will be displayed
# on the repository form instead of the default one.
#
# Examples:
# scm_subversion_path_regexp: file:///svnpath/[a-z0-9_]+
# scm_subversion_path_info: SVN URL (eg. file:///svnpath/foo)
#
# scm_git_path_regexp: /gitpath/%project%(\.[a-z0-9_])?/
#
scm_subversion_path_regexp:
scm_mercurial_path_regexp:
scm_git_path_regexp:
scm_cvs_path_regexp:
scm_bazaar_path_regexp:
scm_darcs_path_regexp:
scm_filesystem_path_regexp:
# Absolute path to the SCM commands errors (stderr) log file.
# The default is to log in the 'log' directory of your Redmine instance.
# Example:
# scm_stderr_log_file: /var/log/redmine_scm_stderr.log
scm_stderr_log_file:
# Key used to encrypt sensitive data in the database (SCM and LDAP passwords).
# If you don't want to enable data encryption, just leave it blank.
# WARNING: losing/changing this key will make encrypted data unreadable.
#
# If you want to encrypt existing passwords in your database:
# * set the cipher key here in your configuration file
# * encrypt data using 'rake db:encrypt RAILS_ENV=production'
#
# If you have encrypted data and want to change this key, you have to:
# * decrypt data using 'rake db:decrypt RAILS_ENV=production' first
# * change the cipher key here in your configuration file
# * encrypt data using 'rake db:encrypt RAILS_ENV=production'
database_cipher_key:
# Set this to false to disable plugins' assets mirroring on startup.
# You can use `rake redmine:plugins:assets` to manually mirror assets
# to public/plugin_assets when you install/upgrade a Redmine plugin.
#
#mirror_plugins_assets_on_startup: false
# Your secret key for verifying cookie session data integrity. If you
# change this key, all old sessions will become invalid! Make sure the
# secret is at least 30 characters and all random, no regular words or
# you'll be exposed to dictionary attacks.
#
# If you have a load-balancing Redmine cluster, you have to use the
# same secret token on each machine.
#secret_token: 'change it to a long random string'
secret_token: 'rake output I generated before and copy-pasta'ed'
# Requires users to re-enter their password for sensitive actions (editing
# of account data, project memberships, application settings, user, group,
# role, auth source management and project deletion). Disabled by default.
# Timeout is set in minutes.
#
#sudo_mode: true
#sudo_mode_timeout: 15
# Absolute path (e.g. /usr/bin/convert, c:/im/convert.exe) to
# the ImageMagick's `convert` binary. Used to generate attachment thumbnails.
#imagemagick_convert_command:
# Configuration of RMagcik font.
#
# Redmine uses RMagcik in order to export gantt png.
# You don't need this setting if you don't install RMagcik.
#
# In CJK (Chinese, Japanese and Korean),
# in order to show CJK characters correctly,
pt/redmine-3.1.0/log/"
# you need to set this configuration.
#
# Because there is no standard font across platforms in CJK,
# you need to set a font installed in your server.
#
# This setting is not necessary in non CJK.
#
# Examples for Japanese:
# Windows:
# rmagick_font_path: C:\windows\fonts\msgothic.ttc
# Linux:
# rmagick_font_path: /usr/share/fonts/ipa-mincho/ipam.ttf
#
rmagick_font_path:
# Maximum number of simultaneous AJAX uploads
#max_concurrent_ajax_uploads: 2
"/opt/redmine-3.1.0/log/"
# Configure OpenIdAuthentication.store
#
# allowed values: :memory, :file, :memcache
#openid_authentication_store: :memory
# specific configuration options for production environment
# that overrides the default ones
production:
# specific configuration options for development environment
# that overrides the default ones
development:"/opt/redmine-3.1.0/log/"
Thanks to Deepak's suggestion I added a "development" section in my database.yml but now I am getting this error:
[user#machinename redmine]$ rake db:migrate
rake aborted!
Psych::SyntaxError: (<unknown>): could not find expected ':' while scanning a simple key at line 52 column 3
/opt/redmine-3.1.0/lib/redmine/configuration.rb:86:in `load_from_yaml'
/opt/redmine-3.1.0/lib/redmine/configuration.rb:42:in `load'
/opt/redmine-3.1.0/lib/redmine/configuration.rb:67:in `[]'
/opt/redmine-3.1.0/lib/redmine/thumbnail.rb:24:in `<module:Thumbnail>'
/opt/redmine-3.1.0/lib/redmine/thumbnail.rb:21:in `<module:Redmine>'
/opt/redmine-3.1.0/lib/redmine/thumbnail.rb:20:in `<top (required)>'
/opt/redmine-3.1.0/lib/redmine.rb:47:in `<top (required)>'
/opt/redmine-3.1.0/config/initializers/30-redmine.rb:6:in `<top (required)>'
/opt/redmine-3.1.0/config/environment.rb:14:in `<top (required)>'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)
Output from #lightalloy's suggestion:
[user#machinename redmine]$ bundle exec rake db:migrate RAILS_ENV=production
rake aborted!
Psych::SyntaxError: (<unknown>): could not find expected ':' while scanning a simple key at line 52 column 3
/opt/redmine-3.1.0/lib/redmine/configuration.rb:86:in `load_from_yaml'
/opt/redmine-3.1.0/lib/redmine/configuration.rb:42:in `load'
/opt/redmine-3.1.0/lib/redmine/configuration.rb:67:in `[]'
/opt/redmine-3.1.0/lib/redmine/thumbnail.rb:24:in `<module:Thumbnail>'
/opt/redmine-3.1.0/lib/redmine/thumbnail.rb:21:in `<module:Redmine>'
/opt/redmine-3.1.0/lib/redmine/thumbnail.rb:20:in `<top (required)>'
/opt/redmine-3.1.0/lib/redmine.rb:47:in `<top (required)>'
/opt/redmine-3.1.0/config/initializers/30-redmine.rb:6:in `<top (required)>'
/opt/redmine-3.1.0/config/environment.rb:14:in `<top (required)>'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/bin/bundle:22:in `load'
/home/XX_USERNAME_XX/.rbenv/versions/2.3.4/bin/bundle:22:in `<main>'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)
I assume that you need to set up the production environment by your database.yml
So you need to specify it when you run rake db:migrate:
bundle exec rake db:migrate RAILS_ENV=production
Make sure you have the configuration for development env in config/database.yml
If not please add the following entry in config/database.yml
# MYSQL
development:
adapter: mysql2
database: development_db
host: localhost
username: username
password: password
encoding: utf8
# # SQLite
# development:
# adapter: sqlite3
# database: db/development.sqlite3
# pool: 5
# timeout: 5000
# # Postgres
# development:
# adapter: postgresql
# encoding: unicode
# database: development_db
# pool: 5
# username: username
# password: password

Rails HStore issue - TypeError: can't cast Hash

Trying to follow this tutorial for setting up an hstore. I've went through and added a preferences hstore to the User model and it all works correctly. Now I've added an exercises hstore to a different model, and this is what I get:
irb(main):128:0* workout = Workout.new
=> #<Workout id: nil, user_id: nil, created_at: nil, updated_at: nil, exercises: nil>
irb(main):129:0> workout.exercises = {
irb(main):130:1* lunges: "10"
irb(main):131:1> }
=> {:lunges=>"10"}
irb(main):132:0> workout.save!
(0.2ms) begin transaction
(1.5ms) rollback transaction
TypeError: can't cast Hash to
from /usr/local/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/quoting.rb:34:in `rescue in type_cast'
from /usr/local/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/quoting.rb:23:in `type_cast'
from /usr/local/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:294:in `block in exec_query'
from /usr/local/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:293:in `map'
from /usr/local/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:293:in `exec_query'
from /usr/local/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:76:in `exec_insert'
from /usr/local/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:108:in `insert'
from /usr/local/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `insert'
from /usr/local/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/relation.rb:64:in `insert'
from /usr/local/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/persistence.rb:521:in `_create_record'
from /usr/local/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/counter_cache.rb:139:in `_create_record'
from /usr/local/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/attribute_methods/dirty.rb:127:in `_create_record'
from /usr/local/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/callbacks.rb:306:in `block in _create_record'
from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:88:in `call'
from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:88:in `_run_callbacks'
from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:734:in `_run_create_callbacks'
... 24 levels...
from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands/console.rb:9:in `start'
from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:68:in `console'
from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `block in require'
from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
from /Users/nomad/Documents/milonos/bin/rails:8:in `<top (required)>'
from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `block in load'
from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
from /usr/local/Cellar/ruby/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /usr/local/Cellar/ruby/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from -e:1:in `<main>'irb(main):133:0>
My migration for creating the Workout model is:
class CreateWorkouts < ActiveRecord::Migration
def change
create_table :workouts do |t|
t.references :user, index: true
t.timestamps null: false
end
add_foreign_key :workouts, :users
end
end
And the migration for adding the hstore:
class AddExercisesToWorkouts < ActiveRecord::Migration
def change
enable_extension "hstore"
add_column :workouts, :exercises, :hstore
add_index :workouts, :exercises, using: :gist
end
end
And my model:
class Workout < ActiveRecord::Base
belongs_to :user
store_accessor :exercises
end
When doing user = User.new and adding hash settings just as above to the preferences hstore, everything seems to work. What am I missing here ?
What I ended up doing was installing postgres and switching from sqlite to it. Then I did rake db:drop db:create db:migrate db:seed, and all the migrations went through. Changed databases.yml to:
# PostgreSQL. Versions 8.2 and up are supported.
#
# Install the pg driver:
# gem install pg
# On OS X with Homebrew:
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On OS X with MacPorts:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
# Choose the win32 build.
# Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
development:
adapter: postgresql
encoding: unicode
database: appname_development
pool: 5
username: username
password:
timeout: 5000
# Connect on a TCP socket. Omitted by default since the client uses a
# domain socket that doesn't need configuration. Windows does not have
# domain sockets, so uncomment these lines.
#host: localhost
# The TCP port the server listens on. Defaults to 5432.
# If your server runs on a different port number, change accordingly.
#port: 5432
# Schema search path. The server defaults to $user,public
#schema_search_path: myapp,sharedapp,public
# Minimum log levels, in increasing order:
# debug5, debug4, debug3, debug2, debug1,
# log, notice, warning, error, fatal, and panic
# Defaults to warning.
#min_messages: notice
# 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: postgresql
encoding: unicode
database: appname_test
pool: 5
username: username
password:
timeout: 5000

PostgreSQL user with Ruby on Rails

I am trying to deploy my app on heroku . For that I changed from sqlite3 to pg because heroku doesn't support sqlite3. I changed things in database.yml:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: postgresql
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.pg
# 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:
<<: *default
database: db/test.pg
production:
<<: *default
database: db/my_database_production.pg
I also did add the gem and install it (gem install pg) . When I try to run bundler exec rake db:create it gives me the following error:
rake aborted!
ActiveRecord::NoDatabaseError: FATAL: role "flo" does not exist
Run `$ bin/rake db:create db:migrate` to create your database
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:898:in `rescue in connect'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `connect'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:568:in `initialize'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:435:in `new_connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:445:in `checkout_new_connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `acquire_connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in `block in checkout'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:350:in `checkout'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:541:in `retrieve_connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_handling.rb:87:in `connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/migration.rb:909:in `initialize'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/migration.rb:807:in `new'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/migration.rb:807:in `up'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/migration.rb:785:in `migrate'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
I am trying to write su - postgres in my terminal but from that command I get :
No passwd entry for user 'postgres'
What should I do ?
You need to add the user 'flo' to your local postgres instance (I usually just add them as a super user so I don't have permissions issues). Run this in your terminal:
createuser -P -s -e flo
You will be prompted to set a password as well. Lets use 'flo' for now. You will then need to add this to your databases.yml file:
development:
<<: *default
database: db/development.pg
username: flo
password: flo
Do that and then try running rake db:create again. Check this out for additional help.

Resetting Test Database via rake test is complaining: "database configuration does not specify adapter"

I am attempting to use this bit of useful code from this question:
namespace :db do
namespace :test do
task :reset do
ActiveRecord::Base.establish_connection('test')
Rake::Task['db:drop'].invoke
Rake::Task['db:create'].invoke
Rake::Task['db:migrate'].invoke
ActiveRecord::Base.establish_connection(ENV['RAILS_ENV']) #Make sure you don't have side-effects!
end
end
end
Unfortunately I am getting this error:
** Invoke db:test:reset (first_time)
** Execute db:test:reset
rake aborted!
database configuration does not specify adapter
/home/nick/.rvm/gems/ruby-1.9.3-p194/gems/activerecord- 3.2.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:45:in `resolve_hash_connection'
/home/nick/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:39:in `resolve_string_connection'
/home/nick/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:25:in `spec'
/home/nick/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:127:in `establish_connection'
/home/nick/Projects/yumbin/lib/tasks/test_environment.rake:4:in `block (3 levels) in <top (required)>'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/home/nick/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
./bundler_stubs/rake:16:in `load'
./bundler_stubs/rake:16:in `<main>'
Tasks: TOP => db:test:reset
As you can see I am using Ruby 1.9.3 via RVM. I am using Rails 3.2.5, Rake version 0.9.2.2 and Postgresql 9.1, and the pg gem (0.13.2). Additionally, I have no database errors in my environments. Thhe app is deployed and running on Heroku, runs locally in development, and I can run my full test suite without issue. In a Rails console running the line:
ActiveRecord::Base.establish_connection('test')
succeeds. I checked the database.yml in vi for invisible characters but could not find any. Only '$' at the end of each line. I'm starting to think that the answer is incredibly simple and in front of my nose but I just can't see it.
UPDATE: Adding my database.yml file:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: postgresql
encoding: unicode
database: myapp-dev
pool: 5
username: ******
password: *******
# 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: postgresql
encoding: unicode
database: myapp-test
pool: 5
username: *****
password: ******
production:
adapter: postgresql
encoding: unicode
database: myapp
pool: 5
username: ******
password: *******
You need a test entry in your database.yml file, and I think you're probably lacking one. Make sure you have an entry that looks like this in database.yml:
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
Using whatever adapter and database your development database is using.

Resources