Skip to content

Commit bbc6fee

Browse files
committed
fix(migrations): use epoch_timestamp instead of epoch for fix_epoch_start migration
1 parent f378f53 commit bbc6fee

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

backend/pkg/commons/db/migrations/clickhouse/20250523100157_fix_epoch_start_in_aggregation.sql

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,59 +31,59 @@ SELECT
3131
validator_index,
3232
balance_start
3333
FROM _final_validator_dashboard_data_epoch
34-
WHERE epoch = GREATEST(
34+
WHERE epoch_timestamp = {genesis_epoch_ts:DateTime} + (GREATEST(
3535
0,
3636
CEIL(
3737
(
3838
toStartOfHour({fork_epoch_ts:DateTime})::DateTime - {genesis_epoch_ts:DateTime}
3939
) / {epoch_duration:Int64}
4040
)
41-
)
41+
) * {epoch_duration:Int64})
4242
UNION ALL
4343
SELECT
4444
epoch,
4545
toStartOfDay({fork_epoch_ts:DateTime}) as t,
4646
validator_index,
4747
balance_start
4848
FROM _final_validator_dashboard_data_epoch
49-
WHERE epoch = GREATEST(
49+
WHERE epoch_timestamp = {genesis_epoch_ts:DateTime} + (GREATEST(
5050
0,
5151
CEIL(
5252
(
5353
toStartOfDay({fork_epoch_ts:DateTime})::DateTime - {genesis_epoch_ts:DateTime}
5454
) / {epoch_duration:Int64}
5555
)
56-
)
56+
) * {epoch_duration:Int64})
5757
UNION ALL
5858
SELECT
5959
epoch,
6060
toMonday({fork_epoch_ts:DateTime}) as t,
6161
validator_index,
6262
balance_start
6363
FROM _final_validator_dashboard_data_epoch
64-
WHERE epoch = GREATEST(
64+
WHERE epoch_timestamp = {genesis_epoch_ts:DateTime} + (GREATEST(
6565
0,
6666
CEIL(
6767
(
6868
toMonday({fork_epoch_ts:DateTime})::DateTime - {genesis_epoch_ts:DateTime}
6969
) / {epoch_duration:Int64}
7070
)
71-
)
71+
) * {epoch_duration:Int64})
7272
UNION ALL
7373
SELECT
7474
epoch,
7575
toStartOfMonth({fork_epoch_ts:DateTime}) as t,
7676
validator_index,
7777
balance_start
7878
FROM _final_validator_dashboard_data_epoch
79-
WHERE epoch = GREATEST(
79+
WHERE epoch_timestamp = {genesis_epoch_ts:DateTime} + (GREATEST(
8080
0,
8181
CEIL(
8282
(
8383
toStartOfMonth({fork_epoch_ts:DateTime})::DateTime - {genesis_epoch_ts:DateTime}
8484
) / {epoch_duration:Int64}
8585
)
86-
)
86+
) * {epoch_duration:Int64})
8787
-- +goose StatementEnd
8888
-- +goose StatementBegin
8989
SYSTEM SYNC REPLICA _tmp_fix_epoch_balance_start LIGHTWEIGHT;

0 commit comments

Comments
 (0)