Heroku. db:push when I app contains two databases - heroku

I have Rails 3.2 application hosted on Heroku. My application contains two databases (one for my model, the second is a kind of a dictionary with static data).
I need to push the second database (dictionary) to Heroku, but when I try db:push Heroku thinks that I'm going to push the first database (with Rails model).
The question is - how could I specify that I want to push my local database dictionary.sqlite to heroku dictionary.pg?

You could use the Heroku pg:transfer plugin which will let you set the target destination by it's URL.
https://github.com/ddollar/heroku-pg-transfer
Alternatively, use psql client locally but restore to the heroku pg isntance.

Don't use db:push/pull; those methods are deprecated. Use pgbackups:capture/restore for things like this. It accepts the HEROKU_POSTGRESQL_COLOR as part of the command:
$ heroku pgbackups:restore HEROKU_POSTGRESQL_COLOR 'https://example.com/data.dump' --app app-name
See Importing and Exporting Heroku Postgres Databases with PG Backups for more detailed explanation.
Also, heroku-pg-transfer has been integrated into pg-extras, check that out here: https://github.com/heroku/heroku-pg-extras

Related

Is a new database created when a Heroku application is forked?

I forked a heroku application (on the cli, using heroku fork). However, when I checked the fork application's config vars, the DATABASE_URL that it's set to is exactly the same as in the original application which I forked.
Can I push database schema changes to the new fork without affecting the original application? Or is there a need to fork the database as well?
From the rather obscure warning in the Heroku documentation, it sounds like sometimes the Heroku Postgres setup in the target app is not 100% correct after forking your app (i.e. as you observed, your DATABASE_URL is still pointing at the original app's DB, instead of at the forked app's DB).
The remedy in this case is to promote the new DB (i.e. your new HEROKU_POSTGRESQL_COLOR_URL) to be the primary DB for the forked app, using heroku pg:promote, e.g:
heroku pg:promote HEROKU_POSTGRESQL_COLOR_URL --app theForkedApp

rails app deployment on heroku - database does not update

Hello I am trying to deploy my rails app from cloud9 via git to heroku. I am able to push all of my changes to git and then push the data to heroku with
git push heroku master
next I migrate my database to heroku
heroku run rake db:migrate
However, when I visit the app on heroku, my data from the database does not show up. How can I fix this?
You're using 2 seperate databases. Migrate doesn't add the data. Just copy the database structure, but it's a new database.
Now you either re-create the data to the database on Heroku or you connect to your local database remotly though database.yml

upgrading to postgres on Heroku

What is the recommended way to upgrade a Heroku Postgres production database to 9.2 with minimal downtime? Is it possible to use a follower, or should we take the pgbackups/snapshots route?
Until logical followers in 9.4, you'll have to dump and restore (for the reasons Craig describes). You can simplify this with pgbackups:transfer. The direct transfer is faster than dump and restore, but know that you won't have a snapshot to keep.
The script below is basically Heroku's Using PG Backups to Upgrade Heroku Postgres Databases
with modification for pgbackups:transfer. (If you have multiple instances, say a staging server, add "-a" or "--remote" to each Heroku line to specify which server.)
# get the pgbackups plugin
heroku plugins:install git://github.com/heroku/heroku-pg-extras.git
# provision new db
heroku addons:add heroku-postgresql:crane --version=9.2
# wait for it to come online, make note of new color
heroku pg:wait
# prevent new data from arriving during dump
heroku ps:scale worker=0 web=0
heroku maintenance:on
# copy over the DB. could take a while.
heroku pgbackups:transfer OLDCOLOR NEWCOLOR
# promote new database as default for DATABASE_URL
heroku pg:promote NEWCOLOR
# start everything back up and test
heroku ps:scale worker=N web=N
heroku maintenance:off
heroku open
# remove old database
heroku addons:remove HEROKU_POSTGRESQL_OLDCOLOR
Note that if you compare your data size between them, the new one may be much smaller because of efficiencies in 9.2. (My 9.2 was about 70% of the 9.1.)
Heroku followers are, AFAIK, just PostgreSQL streaming replica servers. This means you can't use them across versions, you must have binary-compatible databases.
The same techniques should apply as ordinary PostgreSQL, except that you may not be able to use pg_upgrade on Heroku. This requires shell (ssh, etc) access as the postgres user on the system that hosts the database, so I doubt it's possible on Heroku unless they've provided a tool to run pg_upgrade for you. I can't find much information on this.
You will probably have to look at using Slony-I, Bucardo, or another trigger-based replication solution to do the upgrade unless you can find a way to run pg_upgrade on a Heroku database instance. The general idea is that you set up a new 9.2 instance, use Slony to clone data from the 9.1 instance into it, then once they're fully in sync you stop the 9.1 instance, remove the Slony triggers, and switch clients over to the 9.2 instance.
Search for more information on "postgresql low downtime upgrade slony" etc, see how you go.

How do i migrate data between heroku databases?

I have a current 'staging' database in 'heroku' and would like to migrate it into 'production' database? How could I do this? I looked into their taps app but it was not too clear of how it works?
Two options,
PGBackups - https://devcenter.heroku.com/articles/pgbackups - use against your staging database to back it up and then restore to your your production one. Looks at the Transfers sub heading in that page.
Taps via heroku db:pull and heroku db:push - This you would use to pull your staging database to your local machine (doesn't matter what DB you're using locally) and then push it to your production application.
If you're dealing with a large dataset then option 1 is the best option to use. Option 2 also lets you only push specific tables if you uses the --tables <tablenames> argument which is useful in some occasions.

Heroku app with Xeround DB, how to configure?

I’m trying to setup a Heroku app but using a Xeround DB. The instructions I have found are a bit confusing:
http://xeround.com/developers/heroku-cloud-database-mysql/
I'm trying to follow the second way, creating the db directly on Xeround.
My doubts are:
Is the Xeround addon required for this? At least heroku addons:add xeround –app xxxx says: That add-on is only available to selected users
The Heroku DATABASE_URL needs to be set to: mysql://username:password#host:port/database
I've seen some posts with mysql2 and mysql (none has worked for me anyway). My gem file has mysql2, 0.2.7 (for Rails 3.0.x)
I can see the config var ok, but Heroku config --app xxx still shows SHARED_DATABASE_URL => postgres://pjyqfgjcbn:.... is that ok?
Then from the instructions the step #5 is really confusing, it is not clear if that part is optional or not (I expect it is). And if it was mandatory it doesn't tell to which file it has to be added ...
My objective is to create a fresh Heroku app, push an existing app I have, set it up to use the Xeround DB and then run Heroku rake db:schema:load but no matter what I try I keep getting:
rake aborted!
database configuration does not specify adapter
Any ideas how to set it up?
do the same with Rails 3.0.5 but having some problems and comments.
Is the adapter mysql or mysql2? The example on Xeround about the setup site is mysql://username:password#host:port/database
mysql2 is correct gem to use with Rails 3 (mysql 0.2.7 for 3.0.x and latest for 3.1) but the name in the url might be just a name they picked. I guess yours worked but still…
I imagine the Xeround addon of Heroku is not needed right?
heroku addons:add xeround –app xxxx says That add-on is only available to selected users
And finally with mysql or mysql2 in the name of the db url when I try to migrate I just get:
rake aborted!
database configuration does not specify adapter
Did ask Heroku but no answer yet…
I've been using Xeround for several of my apps hosted on Heroku.
I don't have specific experience with Rails. Sinatra only... But hopefully this helps you out.
I do not use the add-on. It's less expensive to setup an account through Xeround on your own.
Connect to it just like you would any MySQL Database....
Connection String will look just like you stated:
mysql://username:password#host:port/database
Host/Port are provided by Xeround in the admin database. Database name would be whatever you setup in phpMyAdmin. User/pass are NOT your Xeround account credentials. They are the credentials you setup for that database instance.
For example... if your ORM is Datamapper... do something like this:
DataMapper.setup(:default, ENV['XEROUND_CONN'])
Or if you're using Sequel:
DB = Sequel.connect(ENV['XEROUND_CONN'])
Then you need to set your XEROUND_CONN (or whatever you wish to call it) ENV variable.
Do this by using the Heroku command
heroku config:add XEROUND_CONN='mysql://username:password#host:port/database'
Warning: Datamapper has an issue with Xeround. Datamapper does not have support for setting your storage engine (myisam..etc..). Xeround uses their own custom Xeround storage engine. So... I've had trouble running auto_migrate due to differences in storage engine.

Resources