Skip to content

Commit

Permalink
feat: add generated by and consumed by id to cell outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
shaojunda committed Jul 18, 2019
1 parent 7b35f3c commit baaefc1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/models/cell_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ class CellOutput < ApplicationRecord
enum status: { live: 0, dead: 1, abandoned: 2 }

belongs_to :ckb_transaction
belongs_to :generated_by, class_name: "CkbTransaction"
belongs_to :consumed_by, class_name: "CkbTransaction"
belongs_to :address
belongs_to :block
has_one :lock_script
Expand Down Expand Up @@ -33,11 +35,15 @@ def address_hash
# block_id :decimal(30, )
# tx_hash :binary
# cell_index :integer
# generated_by_id :decimal(30, )
# consumed_by_id :decimal(30, )
#
# Indexes
#
# index_cell_outputs_on_address_id_and_status (address_id,status)
# index_cell_outputs_on_block_id (block_id)
# index_cell_outputs_on_ckb_transaction_id (ckb_transaction_id)
# index_cell_outputs_on_consumed_by_id (consumed_by_id)
# index_cell_outputs_on_generated_by_id (generated_by_id)
# index_cell_outputs_on_tx_hash_and_cell_index (tx_hash,cell_index)
#
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddGeneratedByAndConsumedByIdToCellOutputs < ActiveRecord::Migration[5.2]
def change
add_column :cell_outputs, :generated_by_id, :decimal, precision: 30, scale: 0
add_column :cell_outputs, :consumed_by_id, :decimal, precision: 30, scale: 0

add_index :cell_outputs, :generated_by_id
add_index :cell_outputs, :consumed_by_id
end
end
4 changes: 4 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,14 @@
t.decimal "block_id", precision: 30
t.binary "tx_hash"
t.integer "cell_index"
t.decimal "generated_by_id", precision: 30
t.decimal "consumed_by_id", 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"
t.index ["tx_hash", "cell_index"], name: "index_cell_outputs_on_tx_hash_and_cell_index"
t.index ["consumed_by_id"], name: "index_cell_outputs_on_consumed_by_id"
t.index ["generated_by_id"], name: "index_cell_outputs_on_generated_by_id"
end

create_table "ckb_transactions", force: :cascade do |t|
Expand Down

0 comments on commit baaefc1

Please sign in to comment.