From 04a80024d07ea82122a106962134e6d0afeff57a Mon Sep 17 00:00:00 2001 From: Vyom Yadav <73882557+Vyom-Yadav@users.noreply.github.com> Date: Thu, 7 Mar 2024 20:43:11 +0530 Subject: [PATCH] Cast sql limit to bigint to force sqlc to generate NullInt64 (#2490) Signed-off-by: Vyom-Yadav --- database/query/repositories.sql | 2 +- docs/docs/ref/proto.md | 2 +- internal/controlplane/handlers_repositories.go | 6 +++--- internal/db/repositories.sql.go | 4 ++-- pkg/api/openapi/minder/v1/minder.swagger.json | 8 ++++---- pkg/api/protobuf/go/minder/v1/minder.pb.go | 6 +++--- proto/buf.yaml | 2 +- proto/minder/v1/minder.proto | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/database/query/repositories.sql b/database/query/repositories.sql index 60f7e324df..4e0d7c5287 100644 --- a/database/query/repositories.sql +++ b/database/query/repositories.sql @@ -32,7 +32,7 @@ SELECT * FROM repositories WHERE provider = $1 AND project_id = $2 AND (repo_id >= sqlc.narg('repo_id') OR sqlc.narg('repo_id') IS NULL) ORDER BY project_id, provider, repo_id -LIMIT sqlc.narg('limit'); +LIMIT sqlc.narg('limit')::bigint; -- name: ListRegisteredRepositoriesByProjectIDAndProvider :many SELECT * FROM repositories diff --git a/docs/docs/ref/proto.md b/docs/docs/ref/proto.md index 3d5bdde124..7e728d0951 100644 --- a/docs/docs/ref/proto.md +++ b/docs/docs/ref/proto.md @@ -915,7 +915,7 @@ The default is to return all user-created profiles; the string "*" can be used t | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | provider | [string](#string) | | **Deprecated.** | -| limit | [int32](#int32) | | | +| limit | [int64](#int64) | | | | context | [Context](#minder-v1-Context) | | | | cursor | [string](#string) | | | diff --git a/internal/controlplane/handlers_repositories.go b/internal/controlplane/handlers_repositories.go index ddec04aa44..1cab8c253c 100644 --- a/internal/controlplane/handlers_repositories.go +++ b/internal/controlplane/handlers_repositories.go @@ -169,13 +169,13 @@ func (s *Server) ListRepositories(ctx context.Context, repoId = sql.NullInt64{Valid: true, Int64: reqRepoCursor.RepoId} } - limit := sql.NullInt32{Valid: false, Int32: 0} + limit := sql.NullInt64{Valid: false, Int64: 0} reqLimit := in.GetLimit() if reqLimit > 0 { if reqLimit > maxFetchLimit { return nil, util.UserVisibleError(codes.InvalidArgument, "limit too high, max is %d", maxFetchLimit) } - limit = sql.NullInt32{Valid: true, Int32: reqLimit + 1} + limit = sql.NullInt64{Valid: true, Int64: reqLimit + 1} } repos, err := s.store.ListRepositoriesByProjectID(ctx, db.ListRepositoriesByProjectIDParams{ @@ -205,7 +205,7 @@ func (s *Server) ListRepositories(ctx context.Context, } var respRepoCursor *cursorutil.RepoCursor - if limit.Valid && len(repos) == int(limit.Int32) { + if limit.Valid && int64(len(repos)) == limit.Int64 { lastRepo := repos[len(repos)-1] respRepoCursor = &cursorutil.RepoCursor{ ProjectId: projectID.String(), diff --git a/internal/db/repositories.sql.go b/internal/db/repositories.sql.go index 9e79c2885e..9668cc9bad 100644 --- a/internal/db/repositories.sql.go +++ b/internal/db/repositories.sql.go @@ -291,14 +291,14 @@ SELECT id, provider, project_id, repo_owner, repo_name, repo_id, is_private, is_ WHERE provider = $1 AND project_id = $2 AND (repo_id >= $3 OR $3 IS NULL) ORDER BY project_id, provider, repo_id -LIMIT $4 +LIMIT $4::bigint ` type ListRepositoriesByProjectIDParams struct { Provider string `json:"provider"` ProjectID uuid.UUID `json:"project_id"` RepoID sql.NullInt64 `json:"repo_id"` - Limit sql.NullInt32 `json:"limit"` + Limit sql.NullInt64 `json:"limit"` } func (q *Queries) ListRepositoriesByProjectID(ctx context.Context, arg ListRepositoriesByProjectIDParams) ([]Repository, error) { diff --git a/pkg/api/openapi/minder/v1/minder.swagger.json b/pkg/api/openapi/minder/v1/minder.swagger.json index 5547c0816d..af7e8dc88a 100644 --- a/pkg/api/openapi/minder/v1/minder.swagger.json +++ b/pkg/api/openapi/minder/v1/minder.swagger.json @@ -1211,8 +1211,8 @@ "name": "limit", "in": "query", "required": false, - "type": "integer", - "format": "int32" + "type": "string", + "format": "int64" }, { "name": "context.provider", @@ -1274,8 +1274,8 @@ "name": "limit", "in": "query", "required": false, - "type": "integer", - "format": "int32" + "type": "string", + "format": "int64" }, { "name": "context.provider", diff --git a/pkg/api/protobuf/go/minder/v1/minder.pb.go b/pkg/api/protobuf/go/minder/v1/minder.pb.go index 77930ee86e..0471f43029 100644 --- a/pkg/api/protobuf/go/minder/v1/minder.pb.go +++ b/pkg/api/protobuf/go/minder/v1/minder.pb.go @@ -2725,7 +2725,7 @@ type ListRepositoriesRequest struct { // Deprecated: Marked as deprecated in minder/v1/minder.proto. Provider string `protobuf:"bytes,1,opt,name=provider,proto3" json:"provider,omitempty"` - Limit int32 `protobuf:"varint,3,opt,name=limit,proto3" json:"limit,omitempty"` + Limit int64 `protobuf:"varint,3,opt,name=limit,proto3" json:"limit,omitempty"` Context *Context `protobuf:"bytes,5,opt,name=context,proto3" json:"context,omitempty"` Cursor string `protobuf:"bytes,6,opt,name=cursor,proto3" json:"cursor,omitempty"` } @@ -2770,7 +2770,7 @@ func (x *ListRepositoriesRequest) GetProvider() string { return "" } -func (x *ListRepositoriesRequest) GetLimit() int32 { +func (x *ListRepositoriesRequest) GetLimit() int64 { if x != nil { return x.Limit } @@ -8746,7 +8746,7 @@ var file_minder_v1_minder_proto_rawDesc = []byte{ 0x73, 0x69, 0x74, 0x6f, 0x72, 0x69, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1e, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x02, 0x18, 0x01, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x12, - 0x14, 0x0a, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, + 0x14, 0x0a, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x2c, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x6d, 0x69, 0x6e, 0x64, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, diff --git a/proto/buf.yaml b/proto/buf.yaml index 1f5ceaaffe..1798d48697 100644 --- a/proto/buf.yaml +++ b/proto/buf.yaml @@ -22,7 +22,7 @@ breaking: - WIRE_JSON except: # Upgrading an int32 to an int64; still accept int32 input, output shape changes - # Undo after #2415 + # Undo after #2490 - FIELD_WIRE_JSON_COMPATIBLE_TYPE lint: use: diff --git a/proto/minder/v1/minder.proto b/proto/minder/v1/minder.proto index bbb169773f..348bece2f0 100644 --- a/proto/minder/v1/minder.proto +++ b/proto/minder/v1/minder.proto @@ -825,7 +825,7 @@ message DeleteRepositoryByNameResponse { message ListRepositoriesRequest { string provider = 1 [deprecated=true]; - int32 limit = 3; + int64 limit = 3; Context context = 5; string cursor = 6;