Skip to content

[Gateway] Add data_version column to gateway-controller artifacts table#2289

Merged
ashera96 merged 2 commits into
wso2:mainfrom
ashera96:gateway/artifact-data-version
Jul 1, 2026
Merged

[Gateway] Add data_version column to gateway-controller artifacts table#2289
ashera96 merged 2 commits into
wso2:mainfrom
ashera96:gateway/artifact-data-version

Conversation

@ashera96

Copy link
Copy Markdown
Contributor

Purpose

Adds a data_version column to the gateway-controller artifacts table to record the data-shape version of each stored artifact (REST API, WebSub API, WebBroker API, LLM Provider, LLM Proxy, MCP Proxy).

The value is <major>.<minor>:

  • major — parsed from the YAML apiVersion suffix (gateway.api-platform.wso2.com/v11).
  • minor — a code-defined constant per kind, starting at 0 (so v11.0). Bump it when a kind's stored data shape changes in a backward-compatible way without bumping apiVersion. Stored rows then record exactly which data shape they were written with, enabling future data migrations.

This decouples the wire/API version (apiVersion, the major) from the stored-data-shape version (the minor).

Changes

  • Schema (3 dialects): data_version added to artifacts after version, matching each dialect's existing style — TEXT NOT NULL DEFAULT '1.0' for SQLite and Postgres, NVARCHAR(20) NOT NULL DEFAULT '1.0' for SQL Server. SQLite schema version bumped 3 → 4 (PRAGMA user_version and currentSchemaVersion).
  • Model: StoredConfig.DataVersion field and a GetApiVersion() helper that prefers SourceConfiguration (the user-authored artifact) and falls back to Configuration (the LLM-derived RestAPI form).
  • Helper: ComputeDataVersion(kind, apiVersion) plus an exhaustive dataMinorVersions map keyed by ArtifactKind.
  • Writes: an ensureDataVersion() chokepoint in SaveConfig, UpdateConfig and UpsertConfig, so every artifact-addition path records a data_version and an explicitly-set value is never overwritten.
  • Reads: data_version threaded through all artifact SELECT/scan paths (single-row reads and the joined scanConfigRows queries).

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@ashera96, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 18 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 659c3fc6-e9c0-4738-b4ab-3c34189416d4

📥 Commits

Reviewing files that changed from the base of the PR and between 290606d and 70a86c6.

📒 Files selected for processing (1)
  • gateway/gateway-controller/pkg/storage/sql_store.go
📝 Walkthrough

Walkthrough

A new data_version field is introduced for gateway-controller artifacts. The models package adds ComputeDataVersion, which derives a "<major>.<minor>" string from the YAML apiVersion and a per-ArtifactKind minor version map, with "1.0" as the default. StoredConfig gains a DataVersion field and a GetApiVersion() method. The artifacts table is extended with a data_version TEXT NOT NULL DEFAULT '1.0' column, and the schema version is bumped to 4 across SQLite, Postgres, and SQL Server. All SQL store write and read paths are updated accordingly.

Suggested Reviewers

  • RakhithaRR
  • pubudu538
  • renuka-fernando
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers purpose and changes, but it omits most required template sections such as goals, approach, tests, and security checks. Add the missing template sections: Goals, Approach, User stories, Documentation, Automation tests, Security checks, Samples, Related PRs, and Test environment.
Docstring Coverage ⚠️ Warning Docstring coverage is 47.37% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding a data_version column to gateway-controller artifacts.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments (1)
gateway/gateway-controller/pkg/storage/sql_store.go (1)

351-358: 🎯 Functional Correctness | 🔵 Trivial

Verify data_version.go map keys against runtime cfg.Kind values.

ArtifactKind is a type alias for string, so the call compiles without explicit conversion. However, ComputeDataVersion relies on a static map (dataMinorVersions) keyed by kind strings. The codebase assigns cfg.Kind using a mix of constants (e.g., models.KindWebSubApi, api.RestAPIKindRestApi) and literals (e.g., "LlmProxy"). If these string values do not exactly match the map keys, the function silently defaults to version 0, bypassing minor version bumps.

Inspect models/data_version.go to confirm the map keys match the string values used in assignments (e.g., "LlmProxy", "RestApi", "WebSubApi").

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@gateway/gateway-controller/pkg/storage/sql_store.go` around lines 351 - 358,
`ensureDataVersion` is passing `cfg.Kind` straight into
`models.ComputeDataVersion`, but the runtime kind strings must exactly match the
`dataMinorVersions` map keys in `models/data_version.go`. Review the `cfg.Kind`
assignments in the storage flow and normalize any mismatched values so they
align with the map entries used by `ComputeDataVersion` (for example `LlmProxy`,
`RestApi`, and `WebSubApi`). If needed, update the map keys or the assigned kind
strings consistently so `ensureDataVersion` never falls back to version `0` for
valid artifact kinds.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@gateway/gateway-controller/pkg/storage/sql_store.go`:
- Around line 351-358: `ensureDataVersion` is passing `cfg.Kind` straight into
`models.ComputeDataVersion`, but the runtime kind strings must exactly match the
`dataMinorVersions` map keys in `models/data_version.go`. Review the `cfg.Kind`
assignments in the storage flow and normalize any mismatched values so they
align with the map entries used by `ComputeDataVersion` (for example `LlmProxy`,
`RestApi`, and `WebSubApi`). If needed, update the map keys or the assigned kind
strings consistently so `ensureDataVersion` never falls back to version `0` for
valid artifact kinds.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1ba53209-0924-49f4-846c-597a1b28435c

📥 Commits

Reviewing files that changed from the base of the PR and between 3f5495d and 3a11551.

📒 Files selected for processing (11)
  • gateway/build-manifest.yaml
  • gateway/gateway-controller/pkg/models/data_version.go
  • gateway/gateway-controller/pkg/models/data_version_test.go
  • gateway/gateway-controller/pkg/models/stored_config.go
  • gateway/gateway-controller/pkg/storage/gateway-controller-db.postgres.sql
  • gateway/gateway-controller/pkg/storage/gateway-controller-db.sql
  • gateway/gateway-controller/pkg/storage/gateway-controller-db.sqlserver.sql
  • gateway/gateway-controller/pkg/storage/sql_store.go
  • gateway/gateway-controller/pkg/storage/sqlite.go
  • gateway/gateway-controller/pkg/storage/sqlite_test.go
  • gateway/gateway-controller/tests/integration/schema_test.go

@ashera96 ashera96 force-pushed the gateway/artifact-data-version branch from 3a11551 to 2a2d107 Compare June 26, 2026 04:37
@ashera96 ashera96 force-pushed the gateway/artifact-data-version branch from 2a2d107 to 290606d Compare June 30, 2026 16:27
gateway_id TEXT NOT NULL,
display_name TEXT NOT NULL,
version TEXT NOT NULL,
data_version TEXT NOT NULL DEFAULT '1.0',

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.

Are we only doing this for artifact table?
cc: @malinthaprasan

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.

Shall we just blindly do it to all the tables? :)
It doesn't do any harm right. No code changes needed as well. Just a default value with 1.0.

@ashera96 ashera96 merged commit da6a048 into wso2:main Jul 1, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants