I'm migrating a PHP app to Rails. The new app has a significantly different schema.
Anybody have experience data from one schema to another? Right now, I'm looking at dumping CSV files and writing Ruby scripts to handle the insertion on the other side. I've also considered using Navicat to export/import to a temp database with the new schema (if it's simple enough), then dump the database and insert the values into a new database using db:seed.
I figure this is gonna be a total pain whichever way I go -- just hoping to minimize the angst. Thanks in advance!
UPDATE:
Decided to export from Navicat into XML, then use Nokogiri to create seed files for Seed_fu.
Check out Dr. Nic's Magic Model Gem. http://magicmodels.rubyforge.org/dr_nic_magic_models/
Then use rake tasks to iterate through your CSVs and insert using the newly generated models.
Related
I am trying to build a read-only Rails API that uses another Rails application's DB as its database.
So far I configured the read-only API's database.yml to point to the existing databases, generated models via rails g model but did not run the migration since I already have the corresponding tables in the existing databases.
I wanted to follow TDD approach and started to write tests but my problem is I cannot create instances of models since I did not create the table for that model.
Example Case
I generated a model named project which exists as a table in the existing DB that I am going to use to read data, but since I did not run the migration for that model it does not exist in the current API's DB.
So, I just dumped the schema.rb from the existing DB, copied it as my read-only API's db/schema.rb and run rake db:schema:load when RAILS_ENV=test.
I wonder if there's a better way to do this? Is my way of writing a read-only API like this is correct? I am open to any suggestions for this topic.
Cheers.
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?
The low-tech approach is to dump your SQLite database into something you can import into your other database. MySQL has LOAD DATA INFILE that'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 _import to 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:
INSERT INTO foo (x,y) SELECT (x,y) FROM _import_foo
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 SELECT on one side and INSERT INTO on the other.
I currently have a system in which one rails 2.3.2 has a database with all of my content data on. I have since created another application which is using rails 3.1 and is very similar but with some more features (hence changed database structure (added and removed columns around the place)).
My issue is that I'm not sure how to get the data (I only really want three values from all of the "entries" (I don't work with databases often and so don't really know the lingo)) in one of my models from one database (SQLite production) to the other (also SQLite production).
I looked into db:seed however it turns out that rails 2.3.2 doesn't support db:seed and so I cannot use this.
Any ideas on how I can do this and easily add the missing information to these entries aswell (such as the published_at column which is new in the newer application which needs to be added for each entry)?
Best Regards,
Joe
If you need to migrate the whole application, check this out: Migrating from Rails 2 to Rails 3
If you only need to manage the sqlite databases, there are a lot of tools to do that. Here's the complete list
I have a Rails project and I used Migrations to setup the database schema (I'm using sqlite3). I have a XML file that I want to insert into my database. What's the best way to approach this? I'm thinking there's some Ruby script that I can write once and use to parse the XML file and insert it into my database, but intuitively it feels like this is a common problem and should have already been automated in the Ruby/Rails world. I guess some people would call this XML shredding, but querying Google hasn't turned up much for me.
Any thoughts?
db/seeds.rb could be a good place to put the data.
I am trying to build a script to automate the update process for symfony projects. E.g. apply any patches from one revision to another including any possible model updates and new fixtures without re-loading the entire database.
I have completed most of it, but I have been unable to find a way to generate an SQL file containing the INSERT statements that get executed by propel load data when it inserts the fixture.
I know that I could dump the database to get the info, but that's not the point and that wouldn't work in my case because I'd need an empty db that has no other data on it.
So in short, my question is: Is there a way to take a fixture YML and generate the SQL inserts necessary?
I know this could be done by processing the yml and building the logic, but the build process it does it somewhere and there's no reason to write that again..
Any help would be much appreciated.
Perhaps I did not understand your question correctly, but couldn't you just call the task that loads the fixtures into the db, or alternatively write code that calls sfPropelData::loadData() (I'm assuming Propel here).
$loader = new sfPropelData();
$loader->loadData(sfConfig::get('sf_data_dir').'/fixtures');
Even sfPropelData and its parent sfData do not generate sql code when loading fixtures, but rather do it using the ORM (as can be seen in sfPropelData::loadDataFromArray().
If you explained your problem more, and why this solution isn't enough, I may be able to help.