This code will transfer data between two different databases. mysql to postgresql is my personal favourite.
It’s very loosely based on the sequel command
code for copying databases, whence the ordering of: transfer schema; then table data;
then recreate indexes and constraints.
And some features that I learned the hard way:
* tables are transferred in chunks of 10000 records, each chunk as a transaction. This keeps memory usage
pretty much constant across the lifetime of the transfer.
* use the Sequel::Dataset#import method,
which will use bulk update statements if the underlying DBMS supports that.
* use yield for progress indicator
It’s not very fast – will transfer a 5Gb database in a couple of hours. If you have bigger data you probably
also have a bigger budget for serious data transfer software ;–)