Created
January 18, 2016 22:47
-
-
Save MatthewRDodds/6f11273f18fededb8416 to your computer and use it in GitHub Desktop.
Refresh Heroku Database (Rails 4)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
heroku pg:reset DATABASE --confirm app_name | |
heroku run rake db:gis:setup | |
heroku run rake db:migrate | |
heroku run rake db:seed |
To test:
heroku run rails runner 'puts RGeo::Geos.supported?'
Add to application.rb
initializer "active_record.initialize_database.override" do |app|
ActiveSupport.on_load(:active_record) do
if url = ENV['DATABASE_URL']
ActiveRecord::Base.connection_pool.disconnect!
parsed_url = URI.parse(url)
config = {
adapter: 'postgis',
host: parsed_url.host,
encoding: 'unicode',
database: parsed_url.path.split("/")[-1],
port: parsed_url.port,
username: parsed_url.user,
password: parsed_url.password
}
establish_connection(config)
end
end
end
Replace in puma config file:
on_worker_boot do
config = ActiveRecord::Base.configurations[Rails.env] ||
Rails.application.config.database_configuration[Rails.env]
config['adapter'] = 'postgis'
ActiveRecord::Base.establish_connection
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To add postgis buildpack: