I have a Ruby on Rails application with a database that is populated with programs. I also have a sqlite3 database that is almost exactly like the database in the RoR app (without created, updated). I want to import the sqlite3 database into the Rails app (not with the database.yml file, combining the two databases) and after much google searching, I can’t figure out how and where to do this. What file where I’d do this in and what would be the best way to do it?
Share
The low-tech approach is to dump your SQLite database into something you can import into your other database. MySQL has
LOAD DATA INFILEthat’s quite flexible and can even read CSV files if configured correctly, so that could be a simple method.Generally I find it’s best to import your external tables as-is but convert the names so they can be identified as being non-native. For instance, prefix all of them with
_importto make it clear they’re not part of your regular schema. You can then migrate from those tables to your native ones using a series of statements that perform the remapping:That makes it easy to account for missing columns or slight differences in names. You can also perform conversion on particular columns if so required.
As always, be sure you have a snapshot of your database before you start this operation as is is usually tricky to un-merge things.
The other approach is to create two database connections simultaneously and shuttle data between the two using
SELECTon one side andINSERT INTOon the other.