Location of Sqlite databases in OSX - ruby-on-rails

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

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.

synching two databases in heroku rails app

I have crm rails application deployed in heroku so my database is postgresql. I have an iphone app which is using mysql database. Now what i need to do is to synch my iphone database with my heroku database.
Can anyone please help me on this is it possible to sync two different databases in heroku
Thanks in Advance
The way we did this was to do it manually
Yep, it's a real pain, but at least you know it's done correctly
--
Process
For migrating from Postgres to MYSQL is as follows:
"Backup" the database using pg_backups
Download the backup locally
In MYSQL (we used PHPMyAdmin), create a series of SQL calls to insert the respective data into the correct tables
Migrating from MYSQL to Postgres is, as much as I can determine, a similar process:
Download the SQL dumps of your MYSQL DB (I only know how to do this in PHPMyAdmin)
Configure those files to be "PG" ready
Send the SQL to your Heroku postgres db's
--
Notes
For specifics, I only have the following:
If you dump from Heroku, you'll not get a traditional SQL file; you'll receive a .dump file. To change this, you'll need to use pg_restore in the following way:
$ cd c:/your/postgres/install/pg_restore/location
$ pg_restore path_to_your_dump.dump > path_to_your_sql.sql
This will give you the ability to "read" the file, uploading to your db & importing as you wish. That's when the fun begins :)
Importing MYSQL
The way to import MYSQL into a PG db will have to be done manually
Although we've never done this directly (we only migrated from PG), there are several things you can do. Firstly, you can use the PG2MYSQL converter to give you an idea as to the syntax differences between MYSQL & PG
Then I would perform a "dump" from MYSQL in SQL format. This will give me the data required for PG. This will allow me to insert into my PG database (you might have to do this locally to give you the ability to determine the syntax), from which you can then patch in the MYSQL data
I understand it's not the most elaborate explanation - I hope it gives you some ideas

Database in Rails application

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/

Rails copy identical app on postgres - data not loading

We have an existing Rails 3 app that has been copied and loaded on a separate server. We've setup the posgres DB for this server; and also configured the database.yaml, pg gems, etc to setup for the port.
However, only the database schema can be migrate...though all the data files has the correct content.
I've tried variations of the db migrate, dump, resets, load, etc. But I'm not success getting the actual data in the database. Again, the server migration is for identical hardware/software config. So, its Rails3.1/Postgres9/Ruby 1.92
I don't get any errors, the data doesn't populate. The ultimate goal is to have an identical app on the 2 servers.
Any ideas? I've already spent 4 days fighting. Many thanks!!
"...the actual data in the database"
If you have an existing database with transactional data - then I think you want to use postgres tools to move the database? maybe I am not understanding the question correctly?
on the source machine
pg_dump DATABASE_NAME > ~/DATABASE_NAME_dump.sql
copy the dump file to the target machine
on the target machine
bundle exec rake db:create
psql DATABASE_NAME < ~/DATABASE_NAME_dump.sql
lots of good information here - http://www.postgresql.org/docs/9.0/static/backup.html
Have you tried the taps gem?
It enables you to transfer schema and data from one instance to another.

Accessing SQLite3 directly?

I am stating out learning Ruby on Rails. For that I am using "Agile Web Development with Rails 4th edition book" which basically walks you through the creation of a sample project.
Even though I am getting the basics down from it I have failed to understand what I believe is a fundamental concept. Where exactly is the relational database and how can I access it directly?
If I was using PHP/MySQL I would go to phpmyadmin and could query the data directly.
How can achieve this with SQLite3?
I am using Linux (Ubuntu) and installed ror and sqlite with gem.
Thanks.
From your Rails root you can access the database command line directly with:
$ sqlite3 db/development.sqlite3
SQLite version 3.7.5
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>
The SQLite3 database is stored in a file, usually located in the db/ folder. If you use Firefox, I recommend the SQLite Manager addon.
You can use other databases if you want to, see 3.3 Configuring a Database in the getting started guide for rails.

Resources