rails mysql2 database...where is it? - ruby-on-rails

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.

Related

How do i figure out what mystery Postgres databases are from my Rails App

I use Aiven.io to manage a PSQL server, inside has multiple databases! Im using it from my rails app, so my rails app uses xxx_production, xxx_development etc.. But i dont remember creating xxx_optimization or metrics databases. The metrics one in particular is 50GB (My xxx_production is only 11GB so this is costing me a lot of extra money)
Is there any way to figure out who created these or why? My suspicion is there is some GEM im using in my rails app that could have created it to keep track of things? No idea what these databases are, and i would delete them but I do want to know what they are so i make sure im not breaking anything.
Thanks!

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?

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.

Heroku PostgreSQL

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.

Freezing database with Rails application

So for a class I have to turn in my Rails application to my professor. What is the best way to make sure everything goes smoothly when he trys to start it up? Also, is there anyway I can freeze a database and send that with it so he has all of the data I have been using in the application?
Thanks a lot.
Depending on your needs, the SQLite3 database (used by default in Rails) is stored on the file system in the db directory of your Rails app. So, assuming your professor has the requirements to run Ruby on Rails, the application will start up with the data you've used.
My guess is you have hard coded connection strings in your rails application. Ask your professor what server he will be running it off of. At that point either change the strings to match or create a config file that is read in and can be edited (which is the better choice of the two). Most databases have export functionality which will allow you to export the current information within the database.

Resources