feat(database): enhance schema configuration for database compatibility

Add support for specifying schema types for the `value` field in the
`ConfigItem` schema. This includes defining `longtext` for MySQL and
`text` for PostgreSQL, enhancing text capacity for this field
This commit is contained in:
sabban 2025-05-06 10:38:31 +02:00
parent e60b3a73cf
commit ebab153ec6
3 changed files with 8 additions and 1 deletions

2
go.sum
View file

@ -561,6 +561,8 @@ github.com/nxadm/tail v1.4.11 h1:8feyoE3OzPrcshW5/MJ4sGESc5cqmGkGCWlco4l0bqY=
github.com/nxadm/tail v1.4.11/go.mod h1:OTaG3NK980DZzxbRq6lEuzgU+mug70nY11sMd4JXXHc=
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=

View file

@ -1,3 +1,4 @@
// +build tools
// Code generated by ent, DO NOT EDIT.
package ent

View file

@ -2,6 +2,7 @@ package schema
import (
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/schema/field"
"github.com/crowdsecurity/crowdsec/pkg/types"
@ -22,7 +23,10 @@ func (ConfigItem) Fields() []ent.Field {
Default(types.UtcNow).
UpdateDefault(types.UtcNow).StructTag(`json:"updated_at"`),
field.String("name").Unique().StructTag(`json:"name"`).Immutable(),
field.String("value").StructTag(`json:"value"`), // a json object
field.String("value").SchemaType(map[string]string{
dialect.MySQL: "longtext",
dialect.Postgres: "text",
}).StructTag(`json:"value"`), // a json object
}
}