From ebab153ec65f5336505ae2ed107da7e8c00ed113 Mon Sep 17 00:00:00 2001 From: sabban Date: Tue, 6 May 2025 10:38:31 +0200 Subject: [PATCH] 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 --- go.sum | 2 ++ pkg/database/ent/runtime.go | 1 + pkg/database/ent/schema/config.go | 6 +++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/go.sum b/go.sum index ece7d98e1..6425f2cf7 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/pkg/database/ent/runtime.go b/pkg/database/ent/runtime.go index 989e67fda..66496437a 100644 --- a/pkg/database/ent/runtime.go +++ b/pkg/database/ent/runtime.go @@ -1,3 +1,4 @@ +// +build tools // Code generated by ent, DO NOT EDIT. package ent diff --git a/pkg/database/ent/schema/config.go b/pkg/database/ent/schema/config.go index d526db25a..2f12f4491 100644 --- a/pkg/database/ent/schema/config.go +++ b/pkg/database/ent/schema/config.go @@ -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 } }