-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from cryptape/add-timestamp-to-tx
Add some columns to blocks and tx
- Loading branch information
Showing
7 changed files
with
46 additions
and
13 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
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
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
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,13 @@ | ||
class AddSomeInfoToBlocks < ActiveRecord::Migration[5.2] | ||
def change | ||
add_column :blocks, :timestamp, :bigint | ||
add_column :blocks, :proposer, :string | ||
add_column :blocks, :quota_used, :decimal, precision: 100 | ||
|
||
reversible do |dir| | ||
dir.up do | ||
execute "UPDATE blocks SET timestamp = subquery.timestamp::bigint, proposer = subquery.proposer::varchar, quota_used = subquery.quota_used::decimal(100) FROM (SELECT (b.header ->> 'timestamp') AS timestamp, (b.header ->> 'proposer') AS proposer, ('x'||lpad(substr((b.header ->> 'quotaUsed'), 3, char_length(b.header ->> 'quotaUsed')), 16, '0'))::bit(64)::bigint AS quota_used, block_hash FROM blocks AS b) AS subquery WHERE subquery.block_hash = blocks.block_hash;" | ||
end | ||
end | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
db/migrate/20181229030703_add_timestamp_to_transactions.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,11 @@ | ||
class AddTimestampToTransactions < ActiveRecord::Migration[5.2] | ||
def change | ||
add_column :transactions, :timestamp, :bigint | ||
|
||
reversible do |dir| | ||
dir.up do | ||
execute %{UPDATE transactions AS tx SET "timestamp" = subquery.timestamp FROM (SELECT block_hash, "timestamp" FROM blocks AS b) AS subquery WHERE tx.block_hash = subquery.block_hash;} | ||
end | ||
end | ||
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
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