Skip to content

Commit 5c48476

Browse files
committed
refac(indexer/schema):adjust aggregate tables similarly to db tables
1 parent f55e7ce commit 5c48476

4 files changed

Lines changed: 30 additions & 37 deletions

File tree

indexer/cli/setup.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,7 @@ user does not have the required privileges.`,
329329
db := timescaledb.NewTimescaleDbSetup(dbConfig)
330330
dbInit := dbinit.NewDBInitializer(db.GetPool())
331331

332-
views := []dbinit.ContinuousAggregateDefinition{
333-
s.TxCounter{},
334-
s.FeeVolume{},
335-
s.DailyActiveAccounts{},
336-
s.ValidatorSigningCounter{},
337-
s.BlockCounter{},
338-
}
332+
views := s.AllAggregates()
339333

340334
l.Info().Msg("refreshing all continuous aggregate views")
341335
for _, v := range views {

pkgs/schema/assertions.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package schema
22

3+
import dbinit "github.com/Cogwheel-Validator/spectra-gnoland-indexer/indexer/db_init"
4+
35
// Assertion here is used as a sort of a linter for the schema.
46
// If some method or parameter is missing it should fail to compile.
57

@@ -59,3 +61,13 @@ var (
5961
_ DBSpecialType = Attribute{}
6062
_ DBSpecialType = Event{}
6163
)
64+
65+
// Continuous aggregate views are materialized views, not plain tables: they must
66+
// satisfy ContinuousAggregateDefinition (mt/fn/gb-driven).
67+
var (
68+
_ dbinit.ContinuousAggregateDefinition = TxCounter{}
69+
_ dbinit.ContinuousAggregateDefinition = FeeVolume{}
70+
_ dbinit.ContinuousAggregateDefinition = DailyActiveAccounts{}
71+
_ dbinit.ContinuousAggregateDefinition = ValidatorSigningCounter{}
72+
_ dbinit.ContinuousAggregateDefinition = BlockCounter{}
73+
)

pkgs/schema/materialize.go

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ func (tc TxCounter) TableName() string {
1919
return "tx_counter"
2020
}
2121

22-
func (tc TxCounter) GetTableInfo() (*dbinit.TableInfo, error) {
23-
return dbinit.GetTableInfo(tc, tc.TableName())
24-
}
25-
2622
func (tc TxCounter) TableColumns() []string {
2723
return aggColumns(tc)
2824
}
@@ -84,10 +80,6 @@ func (dfv FeeVolume) TableName() string {
8480
return "fee_volume"
8581
}
8682

87-
func (dfv FeeVolume) GetTableInfo() (*dbinit.TableInfo, error) {
88-
return dbinit.GetTableInfo(dfv, dfv.TableName())
89-
}
90-
9183
func (dfv FeeVolume) TableColumns() []string {
9284
return aggColumns(dfv)
9385
}
@@ -136,10 +128,6 @@ func (dac DailyActiveAccounts) TableName() string {
136128
return "daily_active_accounts"
137129
}
138130

139-
func (dac DailyActiveAccounts) GetTableInfo() (*dbinit.TableInfo, error) {
140-
return dbinit.GetTableInfo(dac, dac.TableName())
141-
}
142-
143131
func (dac DailyActiveAccounts) TableColumns() []string {
144132
return aggColumns(dac)
145133
}
@@ -193,10 +181,6 @@ func (vds ValidatorSigningCounter) FromTable() string {
193181
return "validator_block_signing"
194182
}
195183

196-
func (vds ValidatorSigningCounter) GetTableInfo() (*dbinit.TableInfo, error) {
197-
return dbinit.GetTableInfo(vds, vds.TableName())
198-
}
199-
200184
func (vds ValidatorSigningCounter) TableColumns() []string {
201185
return aggColumns(vds)
202186
}
@@ -253,10 +237,6 @@ func (dbc BlockCounter) TableName() string {
253237
return "block_counter"
254238
}
255239

256-
func (dbc BlockCounter) GetTableInfo() (*dbinit.TableInfo, error) {
257-
return dbinit.GetTableInfo(dbc, dbc.TableName())
258-
}
259-
260240
func (dbc BlockCounter) TableColumns() []string {
261241
return aggColumns(dbc)
262242
}
@@ -344,3 +324,16 @@ func aggGroupBy(v any) []string {
344324
}
345325
return gb
346326
}
327+
328+
// AllAggregates returns one instance of every continuous aggregate view. It is
329+
// the single canonical list: AllAggrTableNames and the aggregate validation test
330+
// derive from it.
331+
func AllAggregates() []dbinit.ContinuousAggregateDefinition {
332+
return []dbinit.ContinuousAggregateDefinition{
333+
TxCounter{},
334+
FeeVolume{},
335+
DailyActiveAccounts{},
336+
ValidatorSigningCounter{},
337+
BlockCounter{},
338+
}
339+
}

pkgs/schema/table.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,10 @@ func AllTableNames() []string {
245245
}
246246

247247
func AllAggrTableNames() []string {
248-
tables := []DBTable{
249-
TxCounter{},
250-
FeeVolume{},
251-
DailyActiveAccounts{},
252-
ValidatorSigningCounter{},
253-
BlockCounter{},
254-
}
255-
names := make([]string, len(tables))
256-
for i, t := range tables {
257-
names[i] = t.TableName()
248+
aggregates := AllAggregates()
249+
names := make([]string, len(aggregates))
250+
for i, a := range aggregates {
251+
names[i] = a.TableName()
258252
}
259253
return names
260254
}

0 commit comments

Comments
 (0)