MySQL legacy to Rails migration conversion
I have a 5k line MySQL database structure fr开发者_开发百科om a legacy application and need to import this / convert this into a set of Rails db/migration files.
Are there tools out there for doing this? Can one somehow tell Rails to connect to a legacy DB and pull out schema from it?
Thanks.
Rails has this capability built-in.
Point your rails app at the "legacy" schema by modifying database.yml (probably for your development environment).
Run rake db:schema:export
.
Now you have a proper ruby file in the Migrations DSL at db/schema.rb
, which makes it agnostic (which implies it leaves out vendor-specific items too).
Read this article: Migrations – Schema Dumping and You for details.
If you create all of your model with the database structure, you can use it exactly like already is without no change.
After you can do some migration to do more railsway.
This will import your DB and let you output Rails migrations, among other things: SQLEditor
Thanks for the answers. @Georges, I'm running Gentoo. @Shingara - creating all of my models initially would take days.
The end result was (fastest way to do this), unfortunately, to quickly setup a MySQL database server. Bring up the structure. Have Rails do a schema dump (via an app). Then use the newly exported data structure on whatever new database was decided on.
It would be a nice to have - if one could convert the MySQL structure and data dump without having to install any Oracle software on your machine, though.
精彩评论