synching two databases in heroku rails app - ruby-on-rails

I have crm rails application deployed in heroku so my database is postgresql. I have an iphone app which is using mysql database. Now what i need to do is to synch my iphone database with my heroku database.
Can anyone please help me on this is it possible to sync two different databases in heroku
Thanks in Advance

The way we did this was to do it manually
Yep, it's a real pain, but at least you know it's done correctly
--
Process
For migrating from Postgres to MYSQL is as follows:
"Backup" the database using pg_backups
Download the backup locally
In MYSQL (we used PHPMyAdmin), create a series of SQL calls to insert the respective data into the correct tables
Migrating from MYSQL to Postgres is, as much as I can determine, a similar process:
Download the SQL dumps of your MYSQL DB (I only know how to do this in PHPMyAdmin)
Configure those files to be "PG" ready
Send the SQL to your Heroku postgres db's
--
Notes
For specifics, I only have the following:
If you dump from Heroku, you'll not get a traditional SQL file; you'll receive a .dump file. To change this, you'll need to use pg_restore in the following way:
$ cd c:/your/postgres/install/pg_restore/location
$ pg_restore path_to_your_dump.dump > path_to_your_sql.sql
This will give you the ability to "read" the file, uploading to your db & importing as you wish. That's when the fun begins :)
Importing MYSQL
The way to import MYSQL into a PG db will have to be done manually
Although we've never done this directly (we only migrated from PG), there are several things you can do. Firstly, you can use the PG2MYSQL converter to give you an idea as to the syntax differences between MYSQL & PG
Then I would perform a "dump" from MYSQL in SQL format. This will give me the data required for PG. This will allow me to insert into my PG database (you might have to do this locally to give you the ability to determine the syntax), from which you can then patch in the MYSQL data
I understand it's not the most elaborate explanation - I hope it gives you some ideas

Related

How to create dump file from Cloud 9 PostgreSQL database?

I am now working on Cloud 9 and need to see my PostgreSQL database. So I hope to know the below two methods.
How to create dump file from PostgreSQL database when you know database name in Cloud 9?
Which tool can I use to see the tables of PostgreSQL database dump?
Use pg_dump. It looks like Cloud9 doesn't permit remote PostgreSQL connections, so you'll need to run it within the workspace, then transfer the dump file to your computer. Use pg_dump -Fc to make a PostgreSQL-custom-format dump, which is the recommended format.
To list tables in the dump use pg_restore -l to list the dump's table of contents. Generally it's easier to work with dumps by restoring them to a local PostgreSQL install (again, using pg_restore) though.
For more detail see the PostgreSQL manual

How to use pg_dump without using Heroku tools?

I want to use pg_dump on a Heroku multi-schema pgSQL app using the apartment gem, but am afraid I have too many schemas to make it work.
I looked into it and found the following from the creator of the apartment gem at the following link
I'm the author of the Apartment gem that's referenced here. We've been
using it for over a year on Heroku and it utilizes schemas.
It's definitely fine to use, we still get great performance with well
over 100 schemas in an application with 50+ tables per schema.
The article mentioned by #4ware talks about issues with heroku's
pg:backups command. (I'm pretty sure that article came about from our
support queries to them)
It DEFINITELY has issues, but this is not a shortcoming of Postgresql,
schemas or multi-tenancy with schemas, but rather the heroku tool
itself. Now that Postgresql has ingres support on their dbs, you don't
really need to use their built in tools. We just pg_dump when we need
to and it works just as fast as one would expect.
How can I use external tools? Can someone elaborate on this?
I don't know what that person means by "ingres"- certainly not the product, Ingres. Perhaps "ingress", i.e. "inbound"?
In any case: You can make a direct SSL connection to a PostgreSQL database on Heroku using any tool that supports the libpq protocol. That includes psql ... and pg_dump.
Simply:
pg_dump -Fc -f mydb.dbbackup "sslmode=require host=my.heroku.host.name port=5432 dbname=my.heroku.db.name user=my.heroku.user"
(with any other options you want).
See the Heroku documentation for more details.
Note that Heroku database credentials may change, per the docs link above. So if you're automating this or doing it regularly you should use your Heroku account to dynamically fetch the database credentials per the Heroku manual:
pg_dump -Fc -f mydb.dbbackup $(heroku pg:credentials DATABASE)

Rails copy identical app on postgres - data not loading

We have an existing Rails 3 app that has been copied and loaded on a separate server. We've setup the posgres DB for this server; and also configured the database.yaml, pg gems, etc to setup for the port.
However, only the database schema can be migrate...though all the data files has the correct content.
I've tried variations of the db migrate, dump, resets, load, etc. But I'm not success getting the actual data in the database. Again, the server migration is for identical hardware/software config. So, its Rails3.1/Postgres9/Ruby 1.92
I don't get any errors, the data doesn't populate. The ultimate goal is to have an identical app on the 2 servers.
Any ideas? I've already spent 4 days fighting. Many thanks!!
"...the actual data in the database"
If you have an existing database with transactional data - then I think you want to use postgres tools to move the database? maybe I am not understanding the question correctly?
on the source machine
pg_dump DATABASE_NAME > ~/DATABASE_NAME_dump.sql
copy the dump file to the target machine
on the target machine
bundle exec rake db:create
psql DATABASE_NAME < ~/DATABASE_NAME_dump.sql
lots of good information here - http://www.postgresql.org/docs/9.0/static/backup.html
Have you tried the taps gem?
It enables you to transfer schema and data from one instance to another.

Accessing SQLite3 directly?

I am stating out learning Ruby on Rails. For that I am using "Agile Web Development with Rails 4th edition book" which basically walks you through the creation of a sample project.
Even though I am getting the basics down from it I have failed to understand what I believe is a fundamental concept. Where exactly is the relational database and how can I access it directly?
If I was using PHP/MySQL I would go to phpmyadmin and could query the data directly.
How can achieve this with SQLite3?
I am using Linux (Ubuntu) and installed ror and sqlite with gem.
Thanks.
From your Rails root you can access the database command line directly with:
$ sqlite3 db/development.sqlite3
SQLite version 3.7.5
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>
The SQLite3 database is stored in a file, usually located in the db/ folder. If you use Firefox, I recommend the SQLite Manager addon.
You can use other databases if you want to, see 3.3 Configuring a Database in the getting started guide for rails.

How do I check the records of my heroku database?

I've just deployed my application to heroku and pointed my custom domain to the heroku servers. How can I check the records in my heroku database?
You can use heroku run rails console and look at your records with Model.all or any other method.
If you want to backup the database look at heroku PG backups, you then can import your database on your local machine and look at it there. Depending on your db adapter you could use sqlite browser for sqlite3 or phpmyadmin for MySQL.
I found a similar question like this and here is what #Chowlett says:
"You could run heroku pg:psql to fire up a Postgres console, then issue \d to see all tables, and \d tablename to see details for a particular table."
You can also type select * from tablename; to view the table contents.
How to view current database schema for Heroku app in Terminal?
heroku db:pull to pull your production DB locally to take a peek in it.
I'll give the method for connecting via a GUI tool
Run the following command to get the database credentials from Heroku:
heroku pg:credentials DATABASE_URL
Then you can use a GUI tool like PG Commander or PGAdmin to connect to the db
Heroku now has an add-on named PostgreSQL Studio (currently free & in beta) that would let you access your database from within the browser, without having to use CLI, much like PHP MyAdmin.
To attach this add-on to your application,
heroku addons:create pgstudio
Then go to the list of add-ons on Heroku, select PostgreSQL Studio, authorize it, select the database to connect with from the dropdown list of all databases and it will take you to the web-based interface to handle your selected database.
You may refer to this official article on Heroku:
https://devcenter.heroku.com/articles/pgstudio
The easy answer is:
heroku pg:info
You can also download a client side Postgres, like Postico, and using the information provided in that URL to enter password and database name etc, then you can create locally, just like phpMyAdmin.
I use the admin_data gem, works well in Heroku.
You can use heroku dataclips that allows to run queries online. Here you can find documentation https://devcenter.heroku.com/articles/dataclips.
Connect to the database using Sequel Pro. You can find your ClearDB url using heroku config command. The structure for connecting is as follows:
CLEARDB_DATABASE_URL => mysql://[username]:[password]#[host]/[database name]?reconnect=true

Resources