heroku data missing after upgrading database - ruby-on-rails

I have been following heroku docs. and after adding a new db I tried to move my data with: heroku pgbackups:transfer but I noticed that several of the recent entries are missing.. I have tried everything but unable to get those entries synced. I tried using follows and fork but it keeps saying that this feature is for production databases only!!!
I have even raised a ticket, but I doubt if I will get a response soon

Related

"ActionView::Template::Error (Unknown primary key for table" after trying to push local database to Heroku

For a Ruby-on-Rails app that I'm hosting through Heroku, I recently downloaded a backup, restored it locally and then added data to the database from outside sources. That all worked fine.
After the updated database was pushed to Heroku using heroku pg:push <localdbname> HEROKU_DATABASE_URL --app <appname> the app was working fine and I could see the data that was newly added.
However today when I tried to log in to the app on Heroku, I was getting error messages. In my log file I saw this error:
ActionView::Template::Error (Unknown primary key for table ...
According to this SO post: Getting "Unknown primary key for table" while the ID is there
one user was able to get around this problem by resetting and pushing the database to Heroku several times. However, that hasn't worked for me. I've tried to reset and push the database at least 4 times now.
One possibility is that my local postgres database is using version 9.6 and the app is using version 9.4. The Heroku database is a Hobby-Basic database. There is documentation from Heroku on how to upgrade the Postgres version but it's not totally clear from their example what I would need to do. I'm guessing that I basically need to create a new database, copy the data from the old to the new and then destroy the old. Has anyone done this before? Is there a fee associated with doing so? And has upgrading the version of Postgres remotely fixed this issue for other people?
I have ran into similar issues before. I was creating a postgres database outside of rails in RazorSQL. I imported data from outside sources and when I ran it locally everything worked fine. When it came to deployment I ran into all sorts of issues.
I created tables outside of rails thus no migrations were created. I had to recreate the tables by deleting the current model and generating a new model which is a copy of the old one only this time a migration is created for example:
rails generate model ad name:string description:text price:decimal
seller_id:integer email:string img_url:string
I needed to import data from the database I had already created and before I did anything I actually created a seed file using this gem https://github.com/rroblak/seed_dump. All I had to do when I created the model again (remember to delete the model and recreate it) was run rake db:seedand it pulled the data in.
3.The last thing I had to do was insert the assocations in the models for example in a owner model putting in has many: customersto connect the customer model.
Another scenario was I ran a query in RazorSQL and generated a new table from the query and imported it into postgres. The problem was it was only a table from results thus it did not have a primary key. I had to manually create that in postgres using ALTER TABLE test1 ADD COLUMN id SERIAL PRIMARY KEY; This gave me an auto incrementing primary key field and I have to give credit to this answer which helped me https://stackoverflow.com/a/2944561/7039895.
Hope this helps.
According to the docs, you several choices of how to upgrade your database. pg:copy and pg:upgrade.
In your case, I recommand pg:copy: this is easier but required your database to be "off" while your doing the upgrade. This should not be an issue since your database is not currently working.
pg:upgrade should only be used when the downtime required for a PG copy
upgrade is unacceptably long for your business.
Upgrade with PG copy: (All the steps are explain in depth in the link)
Provision new database
You need to create a new database, it will be automatically using the last version of postgresql for heroku (in your case 9.6)
heroku addons:create heroku-postgresql:standard-0
Prevent new database updates
Stop you current database from writing mode to avoid corrupted data while copying to the new
heroku maintenance:on
Transfer data to new database
You need to copy all the data from the old DB to the new.
heroku pg:copy DATABASE_URL HEROKU_POSTGRESQL_PINK --app sushi
Promote new database
You need to notify heroku that you will use the new DB and not the old one.
heroku pg:promote HEROKU_POSTGRESQL_PINK
Last step: Make application active
Everything should be good by now, just make your DB active so it can save new query.
heroku maintenance:off
As you can see, all the steps are straightforward. Therefore, if upgrading you version of postgreSQL doesn't solve the issue, you can still switch back to the old one before removing it.
Pricing
I think it depends of your subscription already (Hobby, Standard or Premium) https://www.heroku.com/pricing. It may be free, or cheap, but I think it also depends of the size of your DB.
To be sure it won't cost you too much, I'm sure you can ask directly to Heroku support https://devcenter.heroku.com/articles/paid-support.

Ruby, ActiveRecord: Local rails server updates record attributes whereas the remote server does not

I have a script which sends data from a Windows back end to Heroku. Recently I added four new columns to the object model. For testing each of the properties is updated individually through a cURL request.
On the local rails server (which is identical to the Heroku hosted server) all four new attributes are populated correctly and there are no errors in the logs.
On the Heroku based server when I run the back end script it updates two of the columns but not the other two. In spite of these values not being populated the logs indicate that the process ran successfully with status of 200.
Has anyone experienced something similar to this?
Ok, managed to resolve this issue.
The solution was to run heroku restart. Seemingly since Heroku apps are precompiled the new columns were not being recognised by the app.
Peculiarly, the app should've probably raised an UnknownAttributeError before the fix was applied.
Cheers,
CBusBus.

Reset database causes heroku custom domain to issue 404

I added a custom domain to my heroku app sometime last week and its been pointing well up until this last night.
A huge error made me reset my database using the heroku pg:reset DATABASE_URL command.
Since then, attempts to visit my app from the custom domain issues a 404, page not found error.
However, when I visit the app directly through its heroku domain name, it works without issues.
I've tried restarting the server, re-adding the domain name even after confirming its there (using heroku domains).
I'd be glad if anyone could help with this error. Thanks.

How to get this simple rails project to work on Heroku?

I followed this tutorial to make a simple website where you can enter blog entries. I was able to get it working with a postgresql database on my computer.
Then I pushed it to heroku. It was accepted and everything seemed fine.
When I tried to go to the page in my browser though, it didn't work right. You can see it here.
I even tried setting up a shared postgresql database on Heroku. Am I supposed to make some changes to database.yml to get it to work?
One thing I noticed though is that what I added in the shared postgresql database, the error messages seem to indicate that it does find a database, but doesn't find the table. Am I right? I tried to manually recreate the table using the heroku console, but wasn't able to.
What's going on here? How can I get this to work?
Have you tried heroku run rake db:migrate yet?
If that doesn't fix it what does heroku logs --tail tell you?

How do I exclude data from local table schema_migrations from being pushed to Heroku DB?

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.
Two possible options:
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.
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.
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.
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.
If your databases are out of sync you can always reset the Heroku database before pushing using
heroku db:reset
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

Resources