Skip to content

Commit

Permalink
feat: add consumed block timestamp to cell output
Browse files Browse the repository at this point in the history
  • Loading branch information
shaojunda committed Jan 3, 2020
1 parent da8381c commit 0f4986f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 18 deletions.
35 changes: 18 additions & 17 deletions app/models/cell_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,24 @@ def flush_cache
#
# Table name: cell_outputs
#
# id :bigint not null, primary key
# capacity :decimal(64, 2)
# data :binary
# ckb_transaction_id :bigint
# created_at :datetime not null
# updated_at :datetime not null
# status :integer default("live")
# address_id :decimal(30, )
# block_id :decimal(30, )
# tx_hash :binary
# cell_index :integer
# generated_by_id :decimal(30, )
# consumed_by_id :decimal(30, )
# cell_type :integer default("normal")
# data_size :integer
# occupied_capacity :decimal(30, )
# block_timestamp :decimal(30, )
# id :bigint not null, primary key
# capacity :decimal(64, 2)
# data :binary
# ckb_transaction_id :bigint
# created_at :datetime not null
# updated_at :datetime not null
# status :integer default("live")
# address_id :decimal(30, )
# block_id :decimal(30, )
# tx_hash :binary
# cell_index :integer
# generated_by_id :decimal(30, )
# consumed_by_id :decimal(30, )
# cell_type :integer default("normal")
# data_size :integer
# occupied_capacity :decimal(30, )
# block_timestamp :decimal(30, )
# consumed_block_timestamp :decimal(30, )
#
# Indexes
#
Expand Down
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
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_12_30_012431) do
ActiveRecord::Schema.define(version: 2020_01_03_051008) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -126,6 +126,7 @@
t.integer "data_size"
t.decimal "occupied_capacity", precision: 30
t.decimal "block_timestamp", precision: 30
t.decimal "consumed_block_timestamp", precision: 30
t.index ["address_id", "status"], name: "index_cell_outputs_on_address_id_and_status"
t.index ["block_id"], name: "index_cell_outputs_on_block_id"
t.index ["ckb_transaction_id"], name: "index_cell_outputs_on_ckb_transaction_id"
Expand Down
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

0 comments on commit 0f4986f

Please sign in to comment.