-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gas outputs): Add Height and ActorName (#270)
* Feat(gas outputs): Add Height and ActorName Gas outputs are very important for many base-fee and gas-usage related views. The table has no height, which means it needs to be joined with blocks all the time on something like state_root to get a timestamp. This is likely innefficient. Additionally, it needs to be joined with actors to get the actor code. Since we are "deriving" and already include redundant info, we might also get this one. This allows easy filtering of messages by actor type and method. * feat(gas outputs): Migrations: add height and actor_name columns * Migration 22: set height to bigint * feat(migrations): add constrains to new derived_gas_outputs columns * feat(migrations): add height column as primary key in derived_gas_outputs. * feat(migrations): re-index gasoutputs_height_code migration to 24. * feat(migrations): fix gas_output_migration. * Add state_root to derived_gas_outputs index Co-authored-by: Ian Davis <[email protected]>
- Loading branch information
Showing
5 changed files
with
105 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package migrations | ||
|
||
import "github.com/go-pg/migrations/v8" | ||
|
||
// Schema version 25 adds Height and ActorName to gas outputs table | ||
|
||
func init() { | ||
up := batch(` | ||
DO $$ | ||
BEGIN | ||
IF ( | ||
SELECT count(*) | ||
FROM information_schema.constraint_column_usage | ||
WHERE table_schema = 'public' | ||
AND table_name = 'derived_gas_outputs' | ||
AND constraint_name='derived_gas_outputs_pkey' | ||
AND column_name IN ('height','cid','state_root') | ||
) != 3 -- want all three columns in the index | ||
THEN | ||
-- Can't change primary key while data exists | ||
TRUNCATE TABLE public.derived_gas_outputs; | ||
ALTER TABLE public.derived_gas_outputs ADD COLUMN height bigint NOT NULL; | ||
ALTER TABLE public.derived_gas_outputs ADD COLUMN actor_name text NOT NULL; | ||
ALTER TABLE public.derived_gas_outputs DROP CONSTRAINT derived_gas_outputs_pkey; | ||
ALTER TABLE public.derived_gas_outputs ADD PRIMARY KEY (height,cid,state_root); | ||
END IF; | ||
END | ||
$$; | ||
`) | ||
down := batch(` | ||
TRUNCATE TABLE public.derived_gas_outputs; | ||
ALTER TABLE public.derived_gas_outputs DROP CONSTRAINT derived_gas_outputs_pkey; | ||
ALTER TABLE public.derived_gas_outputs ADD PRIMARY KEY (cid); | ||
ALTER TABLE public.derived_gas_outputs DROP COLUMN height; | ||
ALTER TABLE public.derived_gas_outputs DROP COLUMN actor_name; | ||
`) | ||
|
||
migrations.MustRegisterTx(up, down) | ||
} |
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