Database in Rails application - ruby-on-rails

I cannot find where the database in my Rails application is located. I looked in folders like /db, /db/migrate, and /app/models, but cannot find the actual database that I can open to examine the data. Where is it located?

Try running rails dbconsole from the command line while you're inside your project directory.

If you're running a SQLite Db (which rails runs by default), you can download SQLite DB Browser (http://sqlitebrowser.sourceforge.net/), and open your db/sqlite3 file to view the actual data, or if you're using mysql, check out: http://www.sequelpro.com/

Related

How to make sqlite3 work in ruby on rails?

I'm trying to start learning ruby on rails and install sqlite3. I actually installed sqlite3 however it doesn't function well like you can see at the bottom.
ruby 2.5.0p0 (2017-12-25 revision 61468) [x64-mingw32]
C:\Users\abc>sqlite3 --v
'sqlite3' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\abc>
Would you tell me how to solve this problem?
Switching to Ubuntu is easier than learning all the hacks required to get Ruby on Rails working on Windows. Once you switch you will never look back, and all the tools you need, like SQLite, will install very easily.
SQLite is an embedded SQL database engine. Unlike most other SQL databases, SQLite does not have a separate server process. SQLite reads and writes directly to ordinary disk files. A complete SQL database with multiple tables, indices, triggers, and views, is contained in a single disk file.
Directly downloadable SQLite .exe file to maintain database SQLite then extract to a folder then open SQLite command toll where you can command for database creation, delete, edit or view
You need marked one .exe file, double-click to open then write command which you need.

Finding Rails DB In Sqlite3

So I created a db with 'sqlite development'. I then ran 'rake db:setup' and it seemed to execute without error. However when I launch the sqlite console, I can't seem to find any of the tables within the development database. Maybe I'm not accessing the database correctly? Any ideas?
Have you done rake db:create? I using that command to create the databases, not manually add the databases.
copied from comment section

Location of Sqlite databases in OSX

Im learning Ruby on Rails 3 and would like to see the db structures created by various Scaffold commands in Sqlite3 in order to understand more the process.
In OSX Snow Leopard, entering:
which sqlite3
yields:
"/usr/local/bin/sqlite3"
However cant seem to find the databases! Pointing to that location merely yields the following error message:
connection failed. file is encrypted or is not a database
To view the dbs im using:
Navicat for Sqlite
anyone enlighten me where the dbs actually reside? "/usr/local/bin/sqlite3" seems to be an symlink to: /usr/local/Cellar/sqlite/3.7.10/bin/sqlite3s
SQLite is actually serverless, so the DB files by default reside in your rails directory.
For example:
/db/development.sqlite3
You can check where all your sqlite environment databases are on config/database.yml

How to load the data from a .sqlite3 file to a Ruby on Rails Application

I have a production.sqlite3 file which I want to import its data to the current rails project, the database schema is match between the file and my current project. I did copy the content to the development.sqlite3 file but this does not work. The only way I know to insert data to the database is by loading some yml file or use the seed command. Is there any magic command or other ways to let the rails loading the data from .sqlite file? Because from what I disover, the behavior of rails is that it only creates the .sqlite3 file when you do rake db:create &migrate, but it will ignore what ever manual changes happen in that file. Please help!
It looks like renaming your .sqlite3 file should work. Make sure you have restarted your server, and that the server is running in the correct environment. If you move both the .sqlite3 files into a completely different folder, and restart the server, an error should occur. If it doesn't, your server didn't properly restart - kill all ruby processes and try again.
In answer to your question about migrating data, I had a similar problem recently, where I had to migrate from sqlite3 to mysql. Best solution I found was yaml_db. It seemed to do the job beautifully - add it to the project, then do
rake db:data:dump
Swap the database configurations (or migrate a new database file, or change your development environment, whatever it is you need to do to make an empty but structured database active), then:
rake db:data:load

Can't connect dumped MongoDB with Rails 3.1 and Mongoid

A Rails 3.1 app is running locally fine with MongoDB and mongoid (until I don't modify anything).
I need the production DB so I dumped it properly. Now I need to configure the Rails app to connect or use this new dumped database.
I copied all the Mongodb's BSON files into the folder where my local Mongo (which started by 'mongod' command) looking for (/data). All files in one folder (/data/e).
How to configure MongoDB or Rails or mongoid.yml to use specifically that folder which I moved there?
+++
Additional info:
Made mongodump successfully. Now I need to import it to the testserver, probably with mongoimport. How to do that?
You don't do that. To dump/restore a MongoDB database, you should use the mongodump and mongorestore utilities

Resources