Forum: Ruby on Rails Transactions and migrations (lots of records)???

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2f9a03aa0fcfe945229cb6126eda2cb2?d=identicon&s=25 Philip Hallstrom (Guest)
on 2006-04-26 01:23
(Received via mailing list)
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
This topic is locked and can not be replied to.