mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-11 22:14:02 +01:00
common/schema: make enabled/disabled columns configurable
This commit is contained in:
@@ -6,14 +6,47 @@
|
||||
// the subsystem that will use it.
|
||||
package schema
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
// Component represents the schema compomenent.
|
||||
type Component struct {
|
||||
c Configuration
|
||||
|
||||
Schema
|
||||
}
|
||||
|
||||
// New creates a new schema component.
|
||||
func New() (*Component, error) {
|
||||
func New(config Configuration) (*Component, error) {
|
||||
schema := flows()
|
||||
for _, k1 := range config.Enabled {
|
||||
for _, k2 := range config.Disabled {
|
||||
if k1 == k2 {
|
||||
return nil, fmt.Errorf("column %q contained in both EnabledColumns and DisabledColumns", k1)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, k := range config.Enabled {
|
||||
if column, ok := schema.LookupColumnByKey(k); ok {
|
||||
column.Disabled = false
|
||||
}
|
||||
}
|
||||
for _, k := range config.Disabled {
|
||||
if column, ok := schema.LookupColumnByKey(k); ok {
|
||||
if column.NoDisable {
|
||||
return nil, fmt.Errorf("column %q cannot be disabled", k)
|
||||
}
|
||||
if slices.Contains(schema.clickHousePrimaryKeys, k) {
|
||||
return nil, fmt.Errorf("column %q cannot be disabled (primary key)", k)
|
||||
}
|
||||
column.Disabled = true
|
||||
}
|
||||
}
|
||||
return &Component{
|
||||
Schema: flows(),
|
||||
c: config,
|
||||
Schema: schema,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user