diff --git a/internal/db/db.go b/internal/db/db.go index 7add89bc64..b3a047f875 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -95,6 +95,9 @@ func Open(dbType DbType, connectionUrl string, opt ...Option) (*DB, error) { wrappedOpts = append(wrappedOpts, dbw.WithLogger(opts.withGormFormatter)) } if opts.withMaxOpenConnections > 0 { + if opts.withMaxOpenConnections < 5 { + return nil, fmt.Errorf("max_open_connections cannot be below 5") + } wrappedOpts = append(wrappedOpts, dbw.WithMaxOpenConnections(opts.withMaxOpenConnections)) } diff --git a/internal/db/db_test.go b/internal/db/db_test.go index d0730c790e..f7f60d12f1 100644 --- a/internal/db/db_test.go +++ b/internal/db/db_test.go @@ -22,6 +22,7 @@ func TestOpen(t *testing.T) { type args struct { dbType DbType connectionUrl string + opt []Option } tests := []struct { name string @@ -44,6 +45,15 @@ func TestOpen(t *testing.T) { }, wantErr: true, }, + { + name: "invalid - max_open_connections set to 3", + args: args{ + dbType: Postgres, + connectionUrl: "", + opt: []Option{WithMaxOpenConnections(3)}, + }, + wantErr: true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {