Steps to reproduce:
rails _7.0.4_ new test --skip-bundle
bundle _2.3.14_ install
rails db:system:change --to=postgresql
Now when trying to run "rails server" the terminal output seems fine but when trying to connect to it via Microsoft Edge browser it just loads indefinitely. "rails server" works before step 6.
When doing "rails db:migrate" it is just stuck in infinite execution without error. See trace below.
Deploying it on Render.com works.
This is the whole project, I'll put it on private once I understand what is happening: https://github.com/Ferdodonna/sample_app
Gemfile before step 6, after step 6 gem "sqlite3", "1.4.2"
becomes gem "pg", "1.4.2
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby "3.1.2"
gem "rails", "7.0.4"
gem "sassc-rails", "2.1.2"
gem "sprockets-rails", "3.4.2"
gem "importmap-rails", "1.1.0"
gem "turbo-rails", "1.1.1"
gem "stimulus-rails", "1.0.4"
gem "jbuilder", "2.11.5"
gem "puma", "5.6.4"
gem "bootsnap", "1.12.0", require: false
group :development, :test do
gem "sqlite3", "1.4.2"
gem "debug", "1.5.0", platforms: %i[ mri mingw x64_mingw ]
end
group :development do
gem "web-console", "4.2.0"
end
group :test do
gem "capybara", "3.37.1"
gem "selenium-webdriver", "4.2.0"
gem "webdrivers", "5.0.0"
gem "rails-controller-testing", "1.0.5"
gem "minitest", "5.15.0"
gem "minitest-reporters", "1.5.0"
gem "guard", "2.18.0"
gem "guard-minitest", "2.4.6"
end
group :production do
gem "pg", "1.3.5"
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem.
# Uncomment the following line if you're running Rails
# on a native Windows system:
gem "tzinfo-data" #, platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Terminal output for "rails server" after step 6
=> Booting Puma
=> Rails 7.0.4 application starting in development
=> Run `bin/rails server --help` for more startup options
*** SIGUSR2 not implemented, signal based restart unavailable!
*** SIGUSR1 not implemented, signal based restart unavailable!
*** SIGHUP not implemented, signal based logs reopening unavailable!
Puma starting in single mode...
* Puma version: 5.6.4 (ruby 3.1.2-p20) ("Birdie's Version")
* Min threads: 5
* Max threads: 5
* Environment: development
* PID: 10656
* Listening on http://[::1]:3000
* Listening on http://127.0.0.1:3000
Use Ctrl-C to stop
Termianl output for "rails db:migrate --trace" after step 6
>rails db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke db:load_config (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:load_config
** Execute db:migrate
Terminal output for aborting "rails db:migrate --trace" after step 6
...
** Execute db:migrate
rails aborted!
Interrupt:
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/pg-1.3.5-x64-mingw-ucrt/lib/pg/connection.rb:627:in `wait_writable'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/pg-1.3.5-x64-mingw-ucrt/lib/pg/connection.rb:627:in `async_connect_or_reset'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/pg-1.3.5-x64-mingw-ucrt/lib/pg/connection.rb:707:in `new'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/pg-1.3.5-x64-mingw-ucrt/lib/pg.rb:69:in `connect'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/postgresql_adapter.rb:78:in `new_client'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:656:in `public_send'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:656:in `new_connection'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:700:in `checkout_new_connection'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:679:in `try_to_checkout_new_connection'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:640:in `acquire_connection'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:341:in `checkout'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:181:in `connection'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract/connection_handler.rb:211:in `retrieve_connection'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_handling.rb:313:in `retrieve_connection'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_handling.rb:280:in `connection'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activerecord-7.0.4/lib/active_record/tasks/database_tasks.rb:262:in `migrate'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activerecord-7.0.4/lib/active_record/railties/databases.rake:92:in `block (2 levels) in <main>'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `block in execute'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `each'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `execute'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `synchronize'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `invoke_with_call_chain'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:188:in `invoke'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rake-13.1.0/lib/rake/application.rb:182:in `invoke_task'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rake-13.1.0/lib/rake/application.rb:138:in `block (2 levels) in top_level'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rake-13.1.0/lib/rake/application.rb:138:in `each'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rake-13.1.0/lib/rake/application.rb:138:in `block in top_level'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rake-13.1.0/lib/rake/application.rb:147:in `run_with_threads'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rake-13.1.0/lib/rake/application.rb:132:in `top_level'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.4/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rake-13.1.0/lib/rake/application.rb:208:in `standard_exception_handling'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.4/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rake-13.1.0/lib/rake/rake_module.rb:59:in `with_application'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.4/lib/rails/commands/rake/rake_command.rb:18:in `perform'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.4/lib/rails/command.rb:51:in `invoke'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.4/lib/rails/commands.rb:18:in `<main>'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.12.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.12.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:migrate
Terminate batch job (Y/N)? y
I tried running rails server
expecting to connect to the application locally.
I tried running 'rails db:migrate`, expecting it to just run through without doing anything, since I didn't implement any database structures yet.
I assume that it tries to connect to a postgresql database that doesn't exist and 'rails server' doesnt emulate. But I am new to Ruby as well as RubyOnRails so I am unsure. Is there a way around that?
Had a look at your config/database.yml on Github. There you have:
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: sample_app_development
Which basically tries to connect to the nonexistent server on localhost. So you have to change this to something like
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
Addionally you may want to change the version strings in your Gemfile:
gem sqlite3, '~> 1.6' #, "1.4.2" --> https://rubygems.org/gems/sqlite3/
gem pg , '~> 1.5' #, "1.3.5" --> https://rubygems.org/gems/pg/
as both gems have received several updates in the past.