Hi all -
I know this must be really easy to do, but I can’t for the life of me
figure it out.
I have about 100,000 rows I need to migrate over into rails using a
migration.
Right now, I select all of them out of the old database and do a series
of:
…
new.col = old.col
…
new.save
…
Problem is each one is it’s own transaction. And it’s slow. I’d like
to
group them into sets of say 50-100 to speed things up a bit.
But the only example regarding transactions I can find are long the
lines
of:
transaction do
david.withdrawal(100)
mary.deposit(100)
end
Which doesn’t really help me.
What I want to do is start a transaction before I start looping then
watch
a counter and every 50th time, commit, then open another one. Then have
a
final commit.
I’ll deal with errors elsewhere… right now I just need it to go
faster.
I have a feeling I want begin_db_transaction and commit_db_transaction,
but I can’t figure out how to use them in the way I want.
Help!
-philip