Skip to content

Schema updates#722

Merged
aangelisc merged 5 commits intomainfrom
andreas/schema-updates
Apr 10, 2026
Merged

Schema updates#722
aangelisc merged 5 commits intomainfrom
andreas/schema-updates

Conversation

@aangelisc
Copy link
Copy Markdown
Contributor

Summary

Cleans up the schemads schema declarations, adds new filter pushdown and timeField table parameter support, and expands test coverage.

Schema cleanup (schema.go)

  • Removed timeRangeOperators — datetime columns no longer declare explicit >, >=, <, <= operators for filter pushdown. Time-based filtering is handled by Grafana's global TimeRange mechanism, so advertising these operators was misleading.
  • Removed equalityOperators from Vulnerabilities severity/state — these columns aren't backed by any pushdown implementation in applyFilters and the GitHub API doesn't support filtering them server-side.

Filter pushdown for Repositories (sql.go)

  • Added pushdown support for is_fork and is_private filters on the Repositories table, translating them into GitHub search qualifiers (fork:only, is:private, is:public).
  • Added QueryTypeDeployments to the tableToQueryType map.

timeField table parameter (schema.go, sql.go)

  • Introduced repoScopedWithTimeFieldTableParameters — extends the standard repo-scoped parameters with an optional timeField parameter.
  • Applied to Issues, Pull Requests, PR Reviews, and Workflows tables.
  • Added timeFieldValuesForTable helper providing valid values per table type (e.g. created, closed, merged, updated).
  • Updated Schema and TableParameterValues handlers to serve timeField values dynamically.
  • Added resolveTimeField / defaultTimeField helpers in sql.go to map user-provided strings (e.g. "merged") to the correct integer enum constant, with sensible defaults per query type.
  • Integrated into normalizeGrafanaSQLRequest so the time range picker filters by the user-selected datetime column.

@aangelisc aangelisc requested a review from a team as a code owner April 10, 2026 12:21
Copilot AI review requested due to automatic review settings April 10, 2026 12:21
@github-project-automation github-project-automation bot moved this to Backlog in OSS Big Tent Apr 10, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the GitHub datasource schemads schema and SQL normalization to better align with actual pushdown behavior, adding repository filter pushdown and a new timeField table parameter to control which datetime column is used for time-range filtering.

Changes:

  • Clean up schema declarations by removing advertised operators that aren’t actually supported/pushed down, and introducing timeField as an optional table parameter for selected tables.
  • Add filter pushdown for repositories (is_fork, is_private) and include deployments in table-to-query-type mapping.
  • Expand test coverage for the new pushdown behavior and timeField normalization/defaulting.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
pkg/github/sql.go Adds repositories filter pushdown; adds timeField resolution/defaulting in SQL request normalization.
pkg/github/schema.go Removes explicit datetime operator advertising; adds timeField table parameter + dynamic value serving.
pkg/github/sql_handler_test.go Extends normalization coverage for deployments, repositories pushdown, and timeField behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/github/sql.go
Comment on lines +358 to +367
switch queryType {
case models.QueryTypeIssues, models.QueryTypePullRequests, models.QueryTypePullRequestReviews, models.QueryTypeWorkflows:
opts, _ := normalized["options"].(map[string]interface{})
if tfStr := strings.TrimSpace(anyToString(query.TableParameterValues["timeField"])); tfStr != "" {
if tf, ok := resolveTimeField(queryType, tfStr); ok {
opts["timeField"] = tf
}
} else {
opts["timeField"] = defaultTimeField(queryType)
}
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If tableParameterValues.timeField is provided but resolveTimeField returns ok=false (invalid/unsupported value), the code currently leaves options.timeField unset. That will cause the downstream JSON unmarshal defaults to kick in (e.g., PRs default to PullRequestClosedAt because enum 0 != the intended default), which is surprising and can change query semantics. Consider falling back to defaultTimeField(queryType) when the provided value is non-empty but unrecognized (and optionally normalizing case with strings.ToLower).

Copilot uses AI. Check for mistakes.
Comment thread pkg/github/sql.go Outdated
case models.QueryTypeIssues:
switch value {
case "created":
return int(models.IssueCreatedAt), true
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it's probably fine but something feels weird about casting to int for every return

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, good nit 😊

@aangelisc aangelisc merged commit b2f4336 into main Apr 10, 2026
23 checks passed
@aangelisc aangelisc deleted the andreas/schema-updates branch April 10, 2026 16:04
@github-project-automation github-project-automation bot moved this from Backlog to Complete in OSS Big Tent Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

3 participants