diff --git a/lib/tasks/migration/generate_referring_cells.rake b/lib/tasks/migration/generate_referring_cells.rake index 135c923e2..3d2c91506 100644 --- a/lib/tasks/migration/generate_referring_cells.rake +++ b/lib/tasks/migration/generate_referring_cells.rake @@ -30,23 +30,21 @@ namespace :migration do contract_hashes = Contract.where(role: "type_script").pluck(:code_hash) binary_hashes = CkbUtils.hexes_to_bins(contract_hashes) contract_type_ids = TypeScript.where(code_hash: binary_hashes).pluck(:id) - live_cells = CellOutput.live.where(type_script_id: contract_type_ids) progress_bar = ProgressBar.create({ total: live_cells.count, format: "%e %B %p%% %c/%C" }) - - live_cells.find_in_batches do |outputs| - outputs.each do |output| - progress_bar.increment - - contract = output.type_script&.contract - - next unless contract - - contracts.each do |contract| - ReferringCell.create_or_find_by( - cell_output_id: output.id, - ckb_transaction_id: output.ckb_transaction_id, - contract_id: contract.id - ) + contract_type_ids.each do |type_id| + puts "============#{type_id}" + progress_bar.increment + live_cells = CellOutput.live.where(type_script_id: type_id) + + live_cells.find_in_batches do |outputs| + outputs.each do |output| + contract = output.type_script&.contract + + ReferringCell.create_or_find_by( + cell_output_id: output.id, + ckb_transaction_id: output.ckb_transaction_id, + contract_id: contract.id + ) end end end