Sinatra app with ActiveRecord died in Passenger 6.0.5

What are you talking about?

I was running a Sinatra app using ActiveRecord on CentOS 8 + Apache 2.4 + Phusion Passenger 6.0. The version of Ruby is 2.7.1, but maybe this version doesn't really matter.

It worked in Passenger 6.0.4, but in 6.0.6 it doesn't even start in production. It is working properly on hand (local).

The Apache error log (/ var / log / httpd / error_log) showed:

'production' database is not configured. Available: [](ActiveRecord::AdapterNotSpecified)

Cause

Apparently it's due to the changes introduced in Passenger 6.0.5. There is an issue here. https://github.com/phusion/passenger/issues/2281

Similar problems can occur outside of Sinatra, but not in Rails (probably).

Dead code

The Sinatra app is as simple as searching for and displaying pre-stored data in the SQLite3 database. Database files are not specifically divided into those for production and those for development.

Where the connection is

ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: db_file)

I wrote it like that. The path of the SQLite3 file is assigned to the local variable db_file.

Fix

Apparently, I have to set ʻActiveRecord :: Base.configurations`, so I'll do the above

ActiveRecord::Base.configurations = {
  "production" => {"adapter" => "sqlite3", "database" => db_file },
  "development" => {"adapter" => "sqlite3", "database" => db_file },
}
ActiveRecord::Base.establish_connection

I changed it like this.

Now it works in production.

Recommended Posts

Sinatra app with ActiveRecord died in Passenger 6.0.5
Decorate your Sinatra app with CSS
Build REST API with Apache2 + Passenger + Sinatra.
Try with resources statement in web app
Practice making a simple chat app with Docker + Sinatra
Implemented pull-down in the original app with Active Hash
Rock-paper-scissors app in Java