Error upgrading from 4.12 to 5.2

There is code in 4.11.80_to_4.13.80.rb


@db.run “ALTER TABLE vm_pool RENAME TO old_vm_pool;”
@db.run “CREATE TABLE vm_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body MEDIUMTEXT, uid INTEGER, gid INTEGER, last_poll INTEGER, state INTEGER, lcm_state INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER);”

@db.run “INSERT INTO vm_pool SELECT * FROM old_vm_pool WHERE state=6;”

log_time()

@db.transaction do
# @db.fetch("SELECT * FROM old_vm_pool WHERE state<>6") do |row|
@db.fetch(“SELECT * FROM old_vm_pool”) do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}

“INSERT INTO vm_pool SELECT * FROM old_vm_pool WHERE state=6;” populate old_vm_pool table with data and subsequent inserts cause violation of primary key. I commented out this line and migration went without errors. Same thing with “INSERT INTO history SELECT * FROM old_history WHERE etime<>0;”"

Maybe I misconfigured something