![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
= heroku_external_db
Allows you to easily set up one or more external databases in Rails applications from Heroku, including the ability to do MySQL connections over SSL. This is useful in the following situations, for example:
== Installation
Add the following to your Gemfile:
gem 'heroku_external_db'
gem 'heroku_external_db', '~> x.y.z'
Then run:
bundle install rails generate heroku_external_db:generator
This will set up a default initializer in your app's +config/initializers/heroku_external_db.rb+.
NOTE: If the generator does not work on your setup, you can copy the initializer by hand.
== Tutorial
The generator makes the assumption that you're happy with using +EXTERNAL_DATABASE_URL+ and (optionally) +EXTERNAL_DATABASE_CA+ as your environment variables and that you want to use the external database as your main production DB. If that's not true, please edit the initializer as needed.
=== Example: MySQL with a CA Certificate
In this example, we are setting up a connection to an external MySQL server using the default initializer.
What we have:
First, we configure Heroku with the appropriate environment variables:
heroku config:add EXTERNAL_DATABASE_CA='ca-cert.pem' heroku config:add EXTERNAL_DATABASE_URL='mysql://username:password@server/dbname'
By default, +heroku_external_db+ looks for the CA cert in +config/ca+, so we need to commit it:
mkdir -p config/ca cp path/to/ca-cert.pem config/ca git add config/ca git commit -v # Using -v since we want to make sure the contents are what we expect (e.g. not a private key)
Additionally, we need the +mysql+ gem in our Gemfile since we are setting up a MySQL server:
echo "gem 'mysql', '~> 2.8.1'" >> Gemfile bundle install # Need Gemfile.lock too
Keep in mind that Heroku installs its own +database.yml+ for Rails apps and we have to install +pg+ as well. Unfortunately, shared databases are mandatory (but are free).
$ heroku addons:remove shared-database:5mb -----> Removing shared-database:5mb from our-app... failed ! Shared databases cannot be removed
PostgreSQL may still be useful to you if, for example, you want to have feature toggles in a local database, but the main data kept externally. However in our case, it also means all developers will need MySQL and PostgreSQL running locally, which is unfortunate.
One workaround is only installing +pg+ in production:
group :production do gem 'pg', '~> 0.11.0' # Regardless of whether you plan to use the database or not, Heroku requires you have 'pg' installed. end
Then +bundle+ like so:
$ bundle install --without production
With our gems updated, commit:
git commit -av # Commit Gemfile and Gemfile.lock
Another option may be overriding +database.yml+ somehow, although it would add complexity. For more info, please see http://stackoverflow.com/questions/4204724/strategies-for-overriding-database-yml.
With our dependencies out of the way, we can move on to testing the connection.
If you are making a new application, you may wish to have a simple MVC for testing that the connection works. E.g., for a blog style application with posts do:
rails generate scaffold post
git add . git commit # ...
With all these changes committed, we can deploy to our Heroku app:
git push heroku master # Your remote may be different
Now, since we are connecting to an existing database, we don't need to run any migrations. (Keep in mind that when sharing a database, it is best to have one authoritative source for migrations to live.) If in your situation you're creating a new database, you may need to do that, run migrations, seed the database, etc at this point.
Open http://our-app.heroku.com and we should see our data. If you happen to run into a problem, please check the logs first:
heroku logs --tail # Again, you may need to specify an app
If you are having a problem, a good starting point is double checking your passwords, usernames, security settings, etc.
=== Example: MySQL with X.509
The process is very much the same as the above example, except two extra environment variables and files are required. Below are the extra steps.
What we have:
First, we configure Heroku with the appropriate environment variables:
heroku config:add EXTERNAL_DATABASE_CA='ca-cert.pem' heroku config:add EXTERNAL_DATABASE_CERT='client-cert.pem' heroku config:add EXTERNAL_DATABASE_KEY='client-key.pem'
By default, +heroku_external_db+ looks for the files in +config/ca+, so we need to commit them:
mkdir -p config/ca cp path/to/ca-cert.pem path/to/client-cert.pem path/to/client-key.pem config/ca git add config/ca git commit
The rest of the process is the same as in "MySQL with a CA Certificate".
== Contributing to heroku_external_db
=== Setting up Environment and Running Specs
./configure rake
== Copyright
Copyright (c) 2011 Nat Budin. See LICENSE.txt for further details.
FAQs
Unknown package
We found that heroku_external_db demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.