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

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.

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.

Heroku PostgreSQL Database - inconsistent enties

i'm working on a Ruby on rails project adopted by another developer. It's deployed on heroku, uses heroku postgreSQL.
When i run the project on my local rails server with the remote database, it works fine. But there is one problem: I would like to delete some entries. So I tried to connect via PostgreSQL-Console. But it seems like the PostgrqSQL-Console gives me another version of the database than the one who is used by the app.
For example, the latest user ID in the app is 540 and in the database displayed by the console only 500.
Any idea? Thank you in advance.
Problem is solved. The elastic search index wasn't synchronized. Thank you for your help anyway.

Rails Tutorial: Why can I sign up a new user without problems on the local server but not on Heroku?

I've completed the Rails Tutorial. I kept up with every detail until the end of chapter 8. The last four chapters I just copied and pasted without trying to understand much.
The Sample App works perfectly on a Cloud9 local web server, but not on Heroku. Specifically, When I want to sign up a new user, I get the message "We're sorry, but something went wrong."
Why can I sign up a new user without problems on the local server but not on Heroku? Is the functionality of the final sample app supposed to be exactly the same on both local and heroku?
You are getting a 500, look at the server logs for a clue. Probably need to run migrations.
Run your migrations:
heroku run rake:db migrate
You may need to restart heroku:
heroku restart
If it still doesn't work, try resetting your database. If you're using postgres, try:
heroku pg:reset DATABASE
I completed every step in the entire Rails Tutorial book, except one, which I thought was optional and wouldn't affect the result in production.
10.3 Email in Production shows you how to configure your application to send emails in production (for account activation in the book's sample application) using a Heroku add-on called Sendgrid.
You do have to give Heroku credit card information (though for the purposes of the book you don't have to actually make any purchase or subscription), and this is why I initially didn't implement this section of the book.
After following along and implementing section 10.3 my final application is fully functional in production.

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.

heroku data missing after upgrading database

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

Resources