views:

503

answers:

6

I was able to push my Ruby on Rails app with MySQL(local dev) to the Heroku server along with migrating my model with the command heroku rake db:migrate. I have also read the documentation on Database Import/Export. Is that doc referring to pushing actual data from my local dev DB to whichever Heroku's DB? Do I need to modify anything in the file database.yml to make it happen?

I ran the following command:

heroku db:push

and I am getting the error:

Sending data
2 tables, 3 records
!!! Caught Server    Exception                                   | ETA:  --:--:--
Taps Server Error: PGError ERROR:  duplicate key value violates unique constraint
"unique_schema_migrations"

I have 2 tables, one I create for my app and the other schema_migrations. The total number of entries among the 2 tables is 3. I'm also printing the number of entries I have in the table I have created and it's showing 0.

Any ideas what I might be missing or what I am doing wrong?

EDIT: I figured out the above, Heroku's DB already have schema_migrations the moment I ran migrate.

New question: Does anyone know how I can exclude data from a specific table from being pushed to Heroku DB. The table to exclude in this case will be schema_migrations.

Not so good solution: I googled around and someone else was having the same issue. He suggested naming the schema_migrations table to zschema_migrations. In this way data from the other tables will be pushed properly until it fails on the last table. It's a pretty bad solution but will do for the time being.

A better solution will be to use an existing Rails command which can reset a specific table from a database. I don't think Rake can do that.

+1  A: 

This is kind of a guess based on the error you're getting, but push looks like it grabs the schema and the data. I'd try push to an empty database.

Andy Gaskell
That kind of help me figure out what's going on. When I first ran `db:migrate`, the table `schema_migrations` gets create on the Heroku DB. When I try to push my local data, it's failing because the value that I have in my local `schema_migrations` is a duplicate of the Heroku. I now need to know how to exclude pushing schema and data from the `schema_migrations` table.
Thierry Lam
If you use db:push I think it will create the whole database. This means you don't need to run db:migrate. Push right after creating the database - which in this case I think means right after you create the Heroku application.
Luke Francl
I tried that but it complains that the schemas have not been created yet on the heroku server which is why running migrate seems to be a first step.
Thierry Lam
+1  A: 

Two possible options:

  1. The heroku gem and the taps gem (which it uses to synchronize databases) are both open-source - you could fork them, alter the taps client API to support excluding tables from a push, then alter the heroku gem to use that new option.

  2. You could write a wrapper script that uses pgdump to backup the schema_migrations table, drops that table, heroku pushes the database, then reloads the table.

Greg Campbell
A: 

A feedback for New question: Does anyone know how I can exclude data from a specific table from being pushed to Heroku DB. The table to exclude in this case will be schema_migrations.

Would it be a problem to have a rake task like this:

and run it like: rake db:clean_tables RAILS_ENV=....

namespace :db do
  namespace :clean_tables do
    desc "cleanup a_table"
      ActiveRecord::Base.connection.execute("delete from a_table")
    end
  end
end
dimus
A: 

I've just deployed a Rails 3 beta app to heroku on their new bamboo server. I can now upload data from my local dev machine to the heroku database by doing:

heroku rake db:fixtures:load test/fixtures/my_model.yml

The data is then properly propagated in the Heroku database. Even though I specified a specific data file, it automatically pushes data from my other yaml files. It probably has something to do with my model relationships.

Thierry Lam
A: 

If your databases are out of sync you can always reset the Heroku database before pushing using

heroku db:reset
Seenmyfate
A: 

To push/pull from specific tables

heroku db:pull --tables logs,tags

http://blog.heroku.com/archives/2010/4/21/supporting_big_data_part_1

Alextoul