When migrating from a legacy system to a greenfield project, the single largest problem you'll face is moving the data. It doesn't have to be all that difficult though.
Join the DZone community and get the full member experience.Join For Free
So your manager has finally given you permission to do the big rewrite, and you're all done, everything is cozy and warm, and you're about to scrap a 10 year old legacy system, to implement the new and shiny stuff. All of a sudden you realise you'll have to export and import 1 million database records from the old system, into the new system, and the database schemas aren't even close to being similar.
Database projections to the rescue
Mandelbrot had a great idea in the 1980s. His idea was that the result of a function could feedback into itself, and end up becoming the input to itself. This of course resulted in a lot of beautiful graphics, even in the Amiga 500 days, and science was in awe of his findings, while small boys had their Amigas rendering fractals on their monitors to impress girls. The punch line was no longer "do you want to see my stamp collection", but more like "do you want to see my Mandelbrot set renderer?"
However, Mandelbrot's ideas have more use cases than simply creating beautiful graphics - For instance, who says that the result of an SQL statement can't produce insert SQL statements?
insert into foo (select * from bar)
When you think about the database migration job like this, projecting data from one database into another actually becomes quite easy. Simply since you can select data from your old database, resulting in insert SQL statements that works for your new database. Let me illustrate with a couple of screenshots.
Step 1, select your data from your old database
Step 2, verify the sanity of your result
Step 3, export your data
Step 4, parametrise your export result, and make sure you choose SQL type
The above little "Mandelbrot trick" allows you to construct any type of SQL select statement, including any amounts of joins, and end up with an insert SQL statement, matching the database schema of your new database. It's really quite simple ^_^
And if you don't want to create a parser yourself, that creates insert statements from your DataReader's results, you can always just simply download Magic, that has this as an integral feature already ...
Opinions expressed by DZone contributors are their own.