Old Rails and PostgreSQL 12 Problem

When your Ruby on Rails is an old version and PostgreSQL is new, you will get the panic error since PostgreSQL 12 doesn’t allow the panic value.

Image by pasja1000 from Pixabay

For example, we’re using Rails v4.2.1 and try to rake db:create

The panic will be at line 313

It’s fixed from panic to warning since Rails v4.2.5 and above.

So, our purpose is to fix warning level for client_min_messages avoid error if Rails < 4.2.5 and PostgreSQL >= 12.

And these are the solutions I found.

Solution A

Update Rails gem to 4.2.5, fix Gemfile gem 'rails' with this

However, if we tried to update the Rails gem, we also need to update other dependency gems when installing the gem. 😛

Solution B

Find the location gem and fix it directly

/Users/pagorn/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb

Use your text editor to edit it. Go to line 313, you should found this code

Change panic to warning It should look like this.

save it and try rake db:create

I do not recommend this way because when we deploy/clone our project to the new environment, we need to fix it for the first time. Your colleagues will not happy. 😒

Solution C

  • Fork Rails repository to your Github
  • Clone it from your fork with specific tag version such as 4.2.1
  • Checkout a new branch from tag
  • Fix the panic to warning
  • commit code and push the new change to remote
  • create tag and push a new tag (optional)

After that, fix Gemfile to point it to branch or tag

  • point to branch
  • or point to tag (optional)

I already made tag v4.2.1.1 on Github for myself 😊

Solution D

Clone the whole rails gem

Paste it in the vendor folder

vendor/gems/rails-4.2.1

Fix the panic similar Solution B, then fix Gemfile

The size of your project folder will be increase by ~22.5MB 🙂

Conclusion

In my opinion, I prefer Solution C and D. It better when you set up and run a project without any additional config.

I also tried the monkey patch solution but doesn’t work with the rake command.

That’s it! Enjoys 🎉

Developer