Heroku PostgreSQL - ruby-on-rails

I need to edit data in my tables at Heroku, how can i do that with an IDE for PostgreSQL or some other solution to this? I'm really new to Heroku, so please can you guide me what's the best way around it.
thanks

To the best of my knowledge, Heroku does not offer direct access to the database. Does heroku console cut it for you? You can access the db through your models directly.
Otherwise you may want to look at how to import/export your database.

If you have access to a dedicated database, you will be able to take advantage of the "ingress" feature to get a raw connection to your database, compatible with all programs that need to speak over the Postgres wire protocol (examples include: psql, pgadmin, navicat, or Microsoft Excel with ODBC -- yes, really, and it's not half bad sometimes!)
But on shared databases you are somewhat out of luck at this time unless you somehow bounce your interactions off ruby and the pg gem.

Alternatively (if you're able to) use db:pull to bring the database locally, do the work locally and then db:push it back up.
Or more likely the easiest option is to do it from console (heroku console at prompt)
John.

for my rails app I use the typus gem which provides a very simple to implement fairly nice db admin interface to the application.

Related

Heroku and database management for rails

I'm getting really close to putting up my first app. However, I'm worried that because I'm so new, I won't know how to manage my database properly.
What's the best practice for managing a database on heroku? As in, backups for example. What if I really screw up something? Can I edit information like usernames, email addresses for users, etc directly in heroku or do I still do that from my terminal?
As Gene mentioned above, you will use pg backup to back up your db. You can do this manually, but you can also schedule backups.
You can easily access the rails console on heroku. Docs here: https://devcenter.heroku.com/articles/getting-started-with-rails4#console
Gook luck rolling your your first app!

Changing database from PostgreSQL to MySQL

I am building an e-commerce application using spree in rails. The application uses PostgreSQL as database. I want it to be changed to MySQL. How do I achieve this?
The short answer is, you don't. I've been through three Spree migrations where we were either using legacy data, or switching databases and trust me; you want nothing to do with this.
If you don't need to take the old data with you, you should be fine just running the migrations on a fresh MySQL database. If you need the legacy data, God be with you...
Converting Spree database schema is nothing nice, and it's hard to just pull what you need out of the database since because almost every data model depends on a foreign key from another. There are dental procedures I would go through voluntarily before attempting what you are proposing. This also begs the question; why do you need to go to MySQL from Postgres?

how to use rails databases? guide?

I am having some trouble understanding how to use databases with ruby on rails. I know that my app works fine when i generate a scaffold and add/edit models. What i do not understand is if anything changes when i put my rails app online, does it still use the .sqlite3 file in the db folder? or do i connect it to my sites SQL server?
If you do switch and connect to a SQL server why is this?
Is there a guide or tutorial on this topic that you can point me to perhaps? my searching mostly came up with migrating tutorials. I just want to figure out how Rails works when it is live on a website.
Thanks
You can use SQLite on production with no problems, although it is not the ideal option.
On production is more recommendable to use a more powerful solution. You can see at the official guide how to switch: http://guides.rubyonrails.org/getting_started.html#configuring-a-database

Moving from SQLite3 to Mongo on Heroku?

I'm currently using SQLite3 with a simple post and image sharing app, similar to the Rails 3 Hartl tutorial (in terms of db structure). But I'd like to move to Mongo for future scalability/learning.
I'm also hosted on Heroku, and am using a 15 GB shared db. I attempted to install MongoHQ and MongoMapper (as per Heroku's instructions) for the transition and this part according to Heroku's support is set up correctly. However, when I turn off the shared db, the app stops working, rather than running off of Mongo.
I'm not sure what do do next, do I have to rewrite my code in mongo or does mongo mapper solve all that? Do I lose my data if I change, if so, how do I copy?
Could any of you please point me to some resources or help me out? Thank you very much!!
MongoDB is not a drop in replacement for a SQL database. There are a couple of things you need to adapt:
The models' code are to be updated to use MongoDB. I can suggest using Mongoid, an ODM, as it will ease your learning path. Mongoid implements Active Record.
The current data saved in your SQL database needs to be migrated - and this is not automatic – to MongoDB schemas. MongoDB do not support migrations as you are used to in SQL world. You will need to write your own scripts for that.
I suggest you write a simple app from scratch using your MongoDB ODM of choice – MongoMapper or Mongoid – so that you get familiar with the basis of MongoDB before attempting to make a migration.

rails mysql2 database...where is it?

yeah, it's pretty stupid. maybe i'm searching for the wrong keywords. where the hell is the db file in the rails folder? I really need to edit stuff and I think it's ridiculous I'm trying to use console and getting a shitload of errors and having trouble deleting records, of all things.
(ie if it was sqlite3, it'd be in the db folder).
....pulls hair out
Rails needs a separate mysql server running either on the same, or a different machine. MySql isn't like sqlite, which uses a text file. Check with your web host, they probably have a MySql database set up already. Use something like Sequel Pro if you want to manipulate the data directly in the database outside of rails.

Resources