Heroku app with Xeround DB, how to configure? - heroku

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.

Related

How to define the database for ActiveRecord migrations when database is hosted

I am using a non-Rails Active Record migration tool, and a hosted Postgres database from Heroku. My dev environment is on Digital Ocean. The production code will be on Heroku.
According to the docs, it seems that the way to connect is through the Database_URL, however, I don't see that as an option for the config.yml file based on the documentation.
What do I put in the development config and production config given the above conditions?
When I create my own tables manually, without using the standalone-migration gem, I used:
ActiveRecord::Base.establish_connection(ENV['POSTGRES_URL'])
but I don't see a similar option to just provide a single URL.
Can I just do the following?
# config.yml
development:
adapter: pg
database: ENV['POSTGRES_URL']
production:
adapter: pg
database: ENV['POSTGRES_URL']

Connecting to existing Heroku Postgres DB for Sinatra app

I am using Salesforce for my CRM, but need to query data (multiple records, so no Zapier) for a Heroku based Sinatra app. Heroku provides a service that replicates Salesforce objects to Postgres tables regularly which gets my data out of Salesforce.
I've coded a Sinatra app before and hosted it on Heroku so I'm a bit familiar with the process of setting up a dev db locally then pushing it to production via the many tutorials. However, i'm running into an issue finding any information that will allow me to connect to the existing production Postgres DB that already is populated with the data I need while having no need to create and connect to a local dev db.
Heroku provides me with the following
How and where to I plug in these various credentials securely so my following files have the right information to connect to tables Venue__c and Spaces__c?
app.rb
/config
- database.yml
- environments.rb
Assuming that you have ActiveRecord, it should just be a case of configuring your database.yml correctly. For example, to directly connect your development environment, use something like:
# database.yml
development:
adapter: postgresql
encoding: unicode
database: your_database
username: your_user
password: your_password
host: your_host
port: your_port
# or alternatively, using the URI
development:
url: postgres://your_user:your_password#your_host/your_database
Heroku publishes your database credentials to you through a URL in an environment variable. You should be able to access it through ENV.fetch("DATABASE_URL"). Depending on your ORM you will use different ways to connect to your database, e.g. Sequel is able to use this value directly as a parameter to Sequel.connect(ENV.fetch("DATABASE_URL")).
As you seem to use ActiveRecord you could be using ActiveRecord::Base.establish_connection(...) as suggested in this post which also exemplifies how to parse the URL (which might not be necessary anymore). This does not translate directly to a database.yml, but since you do not plan to use Rails you will have to provide your own version of environment.rb or some such and it should be easy enough to do in that place.
Turns out Heroku has a great tutorial that not only connects to the replicated database, but is also written for Sinatra.
https://devcenter.heroku.com/articles/getting-started-with-heroku-and-connect-without-local-dev#introduction

Heroku. db:push when I app contains two databases

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

A Sinatra + Datamapper app on Heroku

I've had some problems running an app on Heroku. It uses Sinatra and Datamapper. The full project is here: https://github.com/pixelwolf/phonedb
The problem happens when I deploy the app, all goes well, until I go to the url, where I get an "Application Error" page. I have also push the SQLite3 database using heroku db:push sqlite://database.db
Here are the logs from running heroku logs: https://gist.github.com/1439777
You have to configure your database in datamapper with a line like this
DataMapper.setup(:default, ENV['DATABASE_URL'] || 'sqlite3://my.db')
That was from heroku's website. http://devcenter.heroku.com/articles/database That will configure datamapper to continue to allow you to use sqlite3 on your local machine but switches to Heroku's postgres DB when the application is used there.
Also, Tom Anderson is correct, you need to add the dm-postgres-adapter gem to your Gemfile. I also added the pg gem as well, I'm not sure if that was necessary though.
The error page has the line:
`require': no such file to load -- dm-postgres-adapter
You can only use postgres on heroku. So likely you are not accounting for that in some way. You can develop with sqlite on your machine, but you then need to arrange a few things to make it all work, plus you need to not use any sqlite or postgres only features.
Adapters not working with datamapper
Heroku and Datamapper problems
http://www.ruby-forum.com/topic/1770484

Heroku and Datamapper problems

I can launch a basic app on Heroku, displaying a message with get '/'... works just fine. However, whenever I try to add sqlite with datamapper, the thing breaks down.
In order to see my app structure, check out the project on github. I've kept the code pretty bare-bones.
In the log from heroku I'm getting:
2011-06-26T21:28:36+00:00 app[web.1]: /app/.bundle/gems/ruby/1.9.1/gems/dm-core-1.1.0/lib/dm-core/adapters.rb:163:in `require': no such file to load -- dm-postgres-adapter (LoadError)
The thing about this is that I'm not using postgres, so I'm confused why it is saying this.
"The thing about this is that I'm not using postgres, so I'm confused why it is saying this."
You're using Heroku, so you are using Postgresql.
In your app.rb you have this line:
DataMapper::setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/notes.db")
which I'm guessing you got from the Heroku database docs. This line basically says "check for the environment variable 'DATABASE_URL', and if it's set use it as the database url, otherwise use the Sqlite url". Running locally this environment variable won't be set, so you'll use the Sqlite url, but on Heroku this will be set to something like (see the page linked above):
postgres://username:password#hostname/database
Datamapper will see that this is a Postgresql url, and try to require the postgres adapter, which isn't installed so will result in the error that you see.
The best solution would be to install Postgresql locally, so that your development and production environments are as similar as possible. If you can't do this, or don't want to, you can specify the Sqlite adapter locally, and the Postgres adapter in production. It'll look something like this in your Gemfile:
group :development do
gem 'dm-sqlite-adapter'
end
group :production do
gem 'dm-postgres-adapter'
end
If you do this you'll need to tell Heroku to which groups to leave out when installing gems, see the Heroku Gem Bunder docs.
You are moving from sqlite to postgres-sql and thus you should include dm-postgres-adapter in your Gemfile (and install it ofcourse).
Heroku only supports a read-only file system (or at least only supports read-only operations for any files that you want to be persistent). Hence, you can't use SQLite on Heroku. Heroku only supports PostgreSQL as a database so you need to configure DataMapper to use PostgreSQL (see Yet Another Geek's answer).
I'd recommend installing PostgreSQL in your development environment if you're planning to deploy to Heroku. Every database is a little different and no ORM will protect you from the differences. A bit of searching for questions tagged heroku and postgresql should show some of the problems you'll have if you develop on top of one database but deploy on another.

Resources