Rails - Accessing Another Database? - mysql

I've set up a Rails app using MySQL, with the database 'DatabaseA'. My Rails app is a port of a PHP app that I've written earlier, so there's some data in the PHP app's database (DatabaseB) that I'd like to port over. It's not as simple as an export/import. I've made some schema changes to the database which would require me to manipulate the data first.
What would be the best way to do this? My ideal solution (in the past for PHP) would be to write another controller, and then quickly access DatabaseB and port the data to the new database.

Related

Is it possible to access/edit a remote SQLite3 database with Sequelize from a website

So I have an SQLite3 database with Sequelize on a VPS and a Website I hosted on Hostinger.
Is it possible to access and edit the data in the database from the website?
Any help is appreciated.
[my code is in nodejs]
Yes and No.
Easy and simple answer - now;
Longer - yes, but you would need to map the directories, so server running your sequelize will think it accesses normal directory.
You can download the database, edit it and then send it back. sqlite3 is file database, you dont really connect to it (usually)
SQLite is a database format based on a single file. It's simple but not massively performant. It has no networking features.
The SQLite client needs to have access to the filesystem that the database lives on.
If they are on different computers, then you could do it by using some kind of network filesystem (e.g. via fuse) but this would be really slow.
A better approach would be to run a webservice on the computer the file is stored on, and access the database through there.

connect express js to multiple db (mongo, mysql and neo4j)

A newbie question: I am trying to make an API server using express js. But dont know how to implement connecting to multiple dbs simultaneously like mongodb, mysql and neo4j.
Lets say a call to :
localhost/api/mongodb connects to mongodb
localhost/api/neo4j connects to neo4j
localhost/api/mysql connects to mysql
I am able to connect to each db separately like mongodb using mongoose and so on, but is it possible to make separate calls to each db and perform CRUD operations on them based upon POST/GET etc.

migrating rails app from postgresql to mysql

I'm attempting to migrate my rails application from postgresql to mySQL so as to view the data in one place within xampp in PHPmyadmin. The reason is the fact that I need to access the data that is located within the MySQL database from my rails app which is in postgresql.
As of now most questions I found aim to create a new application within mySQL with rails but I need to migrate all of the data my current rails application compatible and use MySQL.
Is there a proper process and simple procedure that allows for this migration from postgresql to mySQL?
Note: MySQL is within xampp
this post
got the answer to your question.
It's very easy, just paste your postgres dump in this website and you'll get the same dump converted in mysql, ready for you to be imported.
Then you will just need to properly configure your database.yml and you're set.

Where are databases stored in the rails server?

I'm having a lot of run with Ruby, creating some basic web apps. When looking at the logs of the rails server in terminal, I see mysql queries.
Refinery::User Load (0.2ms) SELECT "refinery_users".* FROM "refinery_users" WHERE "refinery_users"."id" = 1 LIMIT 1
Theses are relating to databases that I've created, but where do these databases exist? In the rails server? Where is the rails server stored in OSX? Can I browse what's inside, specifically, the databases?
Thanks, I know this doesn't have much practical use, but I want to understand the concepts behind what's going on, rather than just having superficial knowledge.
By default, Rails uses SQLite3. The database files are stored in the /db directory in the root of your app. There should be a file called development.sqlite3.
To access that database, open a terminal session, go to the root directory of your app and enter sqlite3 db/development.sqlite3. More info on the sqlite shell here: http://www.sqlite.org/sqlite.html
Rather than messing around in the SQLite shell, I think you'd be better off 1) looking at /db/schema.rb to see the structure of your database and 2) using rails console to look at the data.
If you want to know, for any given Rails app, what database it's using, look at /config/database.yml. That gives you the adapter, name of the database, location, etc.
Also, SQLite is generally just for kicking off development. I wouldn't recommend using it when your schema starts getting more complex. Personally, I never use it. I immediately set up a mySQL database for any new Rails projects.

AIR create local SQLite db from downloaded schema file

I'm developing an AIR app which will synchronise data between local SQLite db and server-side MySQL database.
The app is to be used by several users on any number of desktop computers. When a user first installs the AIR app the database and its tables will not exist locally. I would like the app to be able to download a single schema file with all the CREATE TABLE statements and execute them to set up the database tables locally prior to synchronising with server-side data.
I know that flash.data exposes the SQLSchema class which allows inspection of the database schema - but what I would like to do is build a local database from a downloaded schema.
Is this possible?
Thanks in advance.
Best wishes
This is possible.
My way of doing this is through URLRequest which brings back the sql text file with commands to populate tables in main database opened by AIR.