how to use sqlite gem (not DB) on heroku? - ruby-on-rails

I need to parse sqlite files on heroku, and as far as i know Heroku does not support sqlite.
In local, i am using the gem sqlite3, but it is rejected when pushing on heroku.
How can i use 'require sqlite3' in production ?
here is the error:
An error occurred while installing sqlite3 (1.3.6), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v '1.3.6'` succeeds before bundling.
Failed to install gems via Bundler.
Heroku push rejected, failed to compile Ruby/rails app
Thanks in advance

Pretty sure you just don't want to do that: https://devcenter.heroku.com/articles/how-do-i-use-sqlite3-for-development
Heroku doesn't support sqlite and you have to use PostgreSQL. Sorry dude.
This older SO thread has a work around though:
Deploying RoR app to Heroku with Sqlite3 fails
The winning answer there was just use sqlite for dev so: (copy pasting)
group :production, :staging do
gem "pg"
end
group :development, :test do
gem "sqlite3-ruby", "~> 1.3.0", :require => "sqlite3"
end

Related

Not able to create staging instance on heroku [duplicate]

This question already has answers here:
Errors of pushing rails app to Heroku error occurred while installing sqlite3, and Bundler cannot continue [duplicate]
(3 answers)
Closed 7 years ago.
I am trying to create a staging instance of my app on heroku.
While I am doing git push staging master
I am getting
remote: Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
And after this I am getting issues with bundler where It says
An error occurred while installing sqlite3 (1.3.10), and Bundler cannot
remote: continue.
remote: Make sure that gem install sqlite3 -v '1.3.10' succeeds before bundling.
remote: !
remote: ! Failed to install gems via Bundler.
I have the sqlite gem installed, and I installed it manually as well, I am still getting the same error.
Please help.
In your Gemfile
group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor', '0.0.2’
end
and also remove gem 'sqlite3' OR
group :development, :test do
gem 'sqlite3'
end
Because heroku can't install the sqlite3 gem. But you can tell bundler that it shouldn't be trying to except when developing.
Then run bundle install and try to deploy on Heroku.
Heroku does not support sqlite3 database, so you can NOT install sqlite3 gem on Heroku environment. as mentioned in this article, Heroku recommend to use Postgresql as production database.
So, all you need to do is to follow the instruction in that article and replace your sqlite3 gem with pg gem, then do some db configuration.

Pushing Rails to Heroku fails because of sqlite3

I've finished creating my blog in Rails through following this tutorial: http://tutorials.jumpstartlab.com/projects/blogger.html
When I deployed my app to Heroku, I keep getting errors that prevented me from deploying. I've fixed my Gemfile, but I'm still getting the same error.
Here is what the terminal gave me:
An error occurred while installing sqlite3 (1.3.9), and Bundler cannot continue.
Make sure that gem install sqlite3 -v '1.3.9' succeeds before bundling.
!
! Failed to install gems via Bundler.
!
! Detected sqlite3 gem which is not supported on Heroku.
!
! Push rejected, failed to compile Ruby app
Here is what i fixed in my Gemfile:
group :development, :test do
gem 'sqlite3'end
Heroku recommends to use Postgresql instead of sqlite: https://devcenter.heroku.com/articles/sqlite3
so replace gem 'sqlite3'
with
gem 'pg'.
Furthermore, make sure that you use the gem in production. Your example only uses the sqlite gem in :development and in :test.
The result would be:
group :development, :test, :production do
gem 'pg'
end
you could also only use postgres in production:
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pq'
end
However, it is probably best to use the same database in development and production, to avoid any surprises later on.

Rails 4 - Heroku Sqlite3 error

I'm having some trouble with Herouku. I can't push because of the following error:
Gem files will remain installed in /tmp/build_2jdec30lsc3bu/vendor/bundle/ruby/2.0.0/gems/sqlite3-1.3.7 for inspection.
Results logged to /tmp/build_2jdec30lsc3bu/vendor/bundle/ruby/2.0.0/gems/sqlite3-1.3.7/ext/sqlite3/gem_make.out
An error occurred while installing sqlite3 (1.3.7), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v '1.3.7'` succeeds before bundling.
!
! Failed to install gems via Bundler.
!
! Detected sqlite3 gem which is not supported on Heroku.
! https://devcenter.heroku.com/articles/sqlite3
!
! Push rejected, failed to compile Ruby/Rails app
And I can't solve it.
I have tried the following:
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
And I keep getting the same error. I have even tried to remove sqlite3 completely. Same annoying error. I made sure to push my changes before running git push heroku master. Any ideas? Or I will probably give up on Heroku...
I've had similar problems before. This works for me in my Gemfile:
gem 'sqlite3', group: [:development, :test]
gem 'pg', group: [:production]
Also, in your local git checkout, execute the command heroku config. Confirm that the output has the following environment variables set:
RACK_ENV: production
RAILS_ENV: production
Give that a shot. Does it work for you?
How about this?
heroku rake db:reset
heroku rake db:migrate

Cannot deploy Heroku

I have referred to several different sources in order to try to push Heroku..
the error code I'm getting is:
An error occurred while installing sqlite3 (1.3.7), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v '1.3.7'` succeeds before bundling.
Failed to install gems via Bundler.
Heroku push rejected, failed to compile Ruby/rails app
I've tried several Gemfile configurations but this is what I currently have:
group :production, :staging do
gem "pg"
end
group :development, :test do
gem "sqlite3-ruby", "~> 1.3.0", :require => "sqlite3"
end
I've also tried different bundles after.. bundle, bundle install, bundle install --without development
I keep getting the same error.
Please help
Thank you
ps: Please note, I'm new with a lot of this.. So please be as specific as possible.
Thanks again
try (on fedora) or equivalent, and then either install this gem alone or restart the bundle.
yum install sqlite-devel

Heroku deployment failed because of sqlite3 gem error

I just started the ruby.railstutorial.org book by Michael Hartl and have been working through the first chapter. I am using mac book OS X, Terminal, and Sublime Text. Everything has gone according to plan, up until it was time to test deployment to Heroku. I am able to connect to Heroku and run the $ git push heroku master command. But the deployment fails:
Installing sqlite3 (1.3.5) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/usr/local/bin/ruby extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal'
or 'yum install sqlite-devel' and check your shared library search path (the
location where your sqlite3 shared library is located).
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
An error occurred while installing sqlite3 (1.3.5), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v '1.3.5'` succeeds before bundling.
!
! Failed to install gems via Bundler.
!
! Detected sqlite3 gem which is not supported on Heroku.
! http://devcenter.heroku.com/articles/how-do-i-use-sqlite3-for-development
!
! Heroku push rejected, failed to compile Ruby/rails app
Here is my Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.8'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development, :test do
gem 'sqlite3', '1.3.5'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.5'
gem 'coffee-rails', '~> 3.2.2'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.2.3'
end
gem 'jquery-rails', '2.0.2'
group :production do
gem 'pg', '0.12.2'
end
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
I have sqlite3 designated for development and not production, so I thought Heroku would just ignore it all together, but that does not seem to be the case.
Also, when i create the bundle i am using
$ bundle install --without production
I know that some people has suggested to just install PG and use that, but I really want to stick to the tutorial as much as possible, before I venture out and try a different approach.
I am a bit lost at the moment, and not sure how to proceed from here. Any help that you can provide would be most appreciated.
Thanks
Heroku can't install the sqlite3 gem, for whatever reason. But you can tell bundler that it shouldn't be trying to except when developing.
In your Gemfile, replace gem 'sqlite3' with:
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
Then bundler on heroku, running as production, won't try to install it.
I was finally able to deploy successfully to Heroku. Thanks to evanc3 for pointing me to an article on the Heroku site. It appears that I simply forgot to commit my Gemgile updates before deploying to Heroku. So for all of you just starting out, you need to make sure you commit your changes before deploying to Heroku.
Heroku do not support sqlite3...
Remove sqlite3 from your Gemfile, use pg gem instead. Do following change in gem file
change following in your Gemfile
gem 'sqlite3'
to
gem 'pg' #you will have to install postgresql
Important: Run
git add .
git commit
git push heroku master
Note: If you are planning to deploy for heroku, I suggest it is better to use postgres in your development phase also(install postgresql in your computer), heroku prefer psql.
If you want to use sqllite for development and postgresql for Heroku, use following config.
group :development do
gem 'sqlite3' #gem to use in development environment
end
group :production do
gem 'pg' #gem to use in production environment
end
Heroku will use pg gem since heroku run your application in production enviroment
On Heroku, your app doesn't have access to the filesystem. There's a number of reasons for this - it's basically due to the fact that you can scale your app's performance by adding new instances (i.e. running multiple servers at once), and these instances aren't guaranteed to be on the same physical machine - copying the files across would be extremely slow.
SQLite just stores the database to a file in your db/ folder, which is why it's incompatible with Heroku.
The best option, as suggested in the help link, is to move away from SQLite, because there are sometimes subtle incompatibilities between SQLite and PostgreSQL (Heroku's database of choice) and you want to find this out before you deploy to production!
After you install PostgreSQL (exactly how to do this depends on your OS) and then add gem 'pg' to your Gemfile.
I have a solution for if you don't have sqlite3 directly in your gemfile and you're still getting this error.
Most likely, you have a gem that uses sqlite3 as a dependency and it's including the gem without you knowing.
1) Go to Gemfile.lock and do a search for sqlite.
2) Locate which gem is using sqlite then move the gem into the development or test group.
3) Bundle
In Rails Tutorial they have you using sqlite3 in development & pg in production. One reason heroku deployment may fail is if your production deployment on heroku still references sqlite in your database.yml rather than postgres.
tldr; your config/database.yml should match the one shown here:
https://github.com/mhartl/sample_app_6th_ed/blob/main/config/database.yml
most importantly your production config lines should match this (so that adapter: postgres rather than adapter: sqlite3):
production:
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 } %>
database: sample_app_production

Resources