Closed sa-0001 closed 3 years ago
more tests:
new_row = BookModel.find! row.id
), the updated values are presentthis leads me to believe that within the cursor, changes are written to a cached model but not to the database, despite the expected UPDATE query being logged.
mystery solved - normally a cursor (without WITH HOLD
) can only be used within a transaction, so for this script a cursor can't be used, because there are millions of rows that might take days to process, all in the same transaction.
Sorry for the late update. Indeed, you should use pagination API in this case. This might however cause problems if other processes are creating/updating the records at the same time.
could anyone help shed some light, on why the following code does not save any changes?
printing the state of the record, i see that the columns were changed and have the expected values, and
row.changed?
istrue
. however, neitherrow.save
norrow.save!
actually persists any changes.could
each_with_cursor
somehow be creating read-only models, or could it implicitly be within a transaction, ...?puzzlingly, running the same script on a different server, has the correct result (columns are updated in the database).
UPDATE: after deleting
/lib
andshard.lock
and reinstalling dependencies, it now fails on all servers.