-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add consumed block timestamp to cell output
- Loading branch information
Showing
4 changed files
with
45 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
db/migrate/20200103051008_add_consumed_block_timestamp_to_cell_outputs.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddConsumedBlockTimestampToCellOutputs < ActiveRecord::Migration[6.0] | ||
def change | ||
add_column :cell_outputs, :consumed_block_timestamp, :decimal, precision: 30, scale: 0 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
lib/tasks/migration/fill_consumed_block_timestamp_to_dao_cell_output.rake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace :migration do | ||
task fill_consumed_block_timestamp_to_dao_cell_output: :environment do | ||
progress_bar = ProgressBar.create({ | ||
total: CellOutput.count, | ||
format: "%e %B %p%% %c/%C" | ||
}) | ||
|
||
values = | ||
CellOutput.all.map do |cell_output| | ||
progress_bar.increment | ||
[cell_output.id, cell_output.block_id, cell_output.ckb_transaction_id, cell_output.address_id, cell_output.generated_by_id, | ||
cell_output.consumed_by_id, cell_output.consumed_by&.block_timestamp] | ||
end | ||
|
||
columns = [:id, :block_id, :ckb_transaction_id, :address_id, :generated_by_id, :consumed_by_id, :consumed_block_timestamp] | ||
CellOutput.import columns, values, on_duplicate_key_update: [:consumed_block_timestamp] | ||
|
||
puts "done" | ||
end | ||
end |