Skip to content

Commit f378f53

Browse files
committed
fix(migrations): also fix roi aggregates :harold:
1 parent babf112 commit f378f53

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
-- +goose Up
2+
-- +goose StatementBegin
3+
DROP TABLE _insert_sink_backfill_validator_dashboard_data_roi;
4+
-- +goose StatementEnd
5+
-- +goose StatementBegin
6+
CREATE TABLE _insert_sink_backfill_validator_dashboard_data_roi
7+
(
8+
`validator_index` UInt64 COMMENT 'validator index',
9+
`t` DateTime COMMENT 'timestamp of the epoch',
10+
`roi_dividend` Int128 COMMENT 'sum of roi_dividend',
11+
`roi_divisor` Int128 COMMENT 'sum of roi_divisor'
12+
)
13+
ENGINE = Null
14+
-- +goose StatementEnd
15+
-- +goose StatementBegin
16+
DROP VIEW _mv_tmp_final_validator_dashboard_roi_hourly;
17+
-- +goose StatementEnd
18+
-- +goose StatementBegin
19+
CREATE MATERIALIZED VIEW _mv_tmp_final_validator_dashboard_roi_hourly TO _final_validator_dashboard_roi_hourly
20+
(
21+
`validator_index` UInt64,
22+
`t` DateTime,
23+
`roi_dividend` Int128,
24+
`roi_divisor` Int128
25+
)
26+
AS SELECT
27+
validator_index AS validator_index,
28+
toStartOfHour(t) AS t,
29+
sum(CAST(foo.roi_dividend, 'Int128')) AS roi_dividend,
30+
sum(CAST(foo.roi_divisor, 'Int128')) AS roi_divisor
31+
FROM _insert_sink_backfill_validator_dashboard_data_roi AS foo
32+
GROUP BY
33+
t,
34+
validator_index;
35+
-- +goose StatementEnd
36+
-- +goose StatementBegin
37+
TRUNCATE TABLE _final_validator_dashboard_roi_hourly;
38+
-- +goose StatementEnd
39+
-- +goose StatementBegin
40+
TRUNCATE TABLE _final_validator_dashboard_roi_daily;
41+
-- +goose StatementEnd
42+
-- +goose StatementBegin
43+
TRUNCATE TABLE _final_validator_dashboard_roi_weekly;
44+
-- +goose StatementEnd
45+
-- +goose StatementBegin
46+
TRUNCATE TABLE _final_validator_dashboard_roi_monthly;
47+
-- +goose StatementEnd
48+
ALTER TABLE _exporter_backfill_metadata DELETE WHERE backfill_name = 'roi';
49+
-- +goose StatementBegin
50+
/* set the highest epoch the backfill process should backfill */
51+
INSERT INTO _exporter_backfill_metadata
52+
SELECT
53+
epoch,
54+
'roi' as backfill_name,
55+
transfer_batch_id as backfill_batch_id,
56+
NULL AS successful_backfill
57+
FROM
58+
(
59+
SELECT *
60+
FROM _exporter_metadata
61+
WHERE successful_transfer IS NOT NULL
62+
ORDER BY epoch DESC
63+
LIMIT 1
64+
)
65+
-- +goose StatementEnd
66+
67+
68+
-- +goose Down
69+
-- +goose StatementBegin
70+
71+
-- +goose StatementEnd

0 commit comments

Comments
 (0)