Skip to content

feat: adds gorm level foreign key constraint to models in oapi spec#120

Merged
semmet95 merged 2 commits into
mainfrom
feat/gorm-sql-constarints
May 27, 2026
Merged

feat: adds gorm level foreign key constraint to models in oapi spec#120
semmet95 merged 2 commits into
mainfrom
feat/gorm-sql-constarints

Conversation

@semmet95
Copy link
Copy Markdown
Contributor

@semmet95 semmet95 commented May 27, 2026

Summary by CodeRabbit

  • Refactor

    • Enhanced data model relationships and added comprehensive validation constraints to improve data consistency and integrity.
    • Implemented stricter indexing and uniqueness requirements across key data fields.
  • Tests

    • Updated test suites to validate referential integrity and enforce relationship constraints.

Review Change Stack

Signed-off-by: Amit Singh <singhamitch@outlook.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 27, 2026

Warning

Review limit reached

@semmet95, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 24 minutes and 59 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

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.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 49cf8759-b9fc-4a98-b53c-162f1f6101ab

📥 Commits

Reviewing files that changed from the base of the PR and between ac4d1ca and b1b95bf.

📒 Files selected for processing (3)
  • api/source-score.yaml
  • pkg/api/server.gen.go
  • pkg/domain/claim/claim_service_test.go
📝 Walkthrough

Walkthrough

This PR introduces database schema relationships between Source, Claim, and Proof entities through OpenAPI schema definitions and GORM constraints. The changes are reflected in code generation, test infrastructure, and service tests, establishing foreign key relationships and data integrity constraints across the domain layer.

Changes

Database Schema Relationships and Constraints

Layer / File(s) Summary
OpenAPI schema relationships and constraints
api/source-score.yaml
Source, Claim, and Proof schemas gain GORM relationship fields and database constraints. Claim adds a source field referencing Source via sourceUriDigest. Proof adds a claim field referencing Claim via claimUriDigest. Multiple properties receive not-null, default, uniqueness, and indexing constraints.
Generated Go struct mappings
pkg/api/server.gen.go
Generated structs reflect schema changes with GORM tags and relationship fields. Claim includes optional Source field with updated SourceUriDigest metadata. Proof includes optional Claim field. Source fields gain explicit GORM constraints for not-null, defaults, unique indexes, and primary key sizing.
Test database foreign key enforcement and sample data
pkg/domain/claim/claim_suite_test.go, pkg/domain/source/source_suite_test.go, pkg/domain/proof/proof_suite_test.go
SQLite test databases enable foreign key constraints via DSN parameter across all suites. Proof test suite expands sampleSource with required fields, derives sampleClaim.SourceUriDigest from sampleSource.UriDigest, and explicitly persists sampleSource before sampleClaim to respect foreign key relationships.
Service test updates for relationship structure
pkg/domain/claim/claim_service_test.go
Test refactoring changes repository stubbing to use dynamic call counts instead of fixed indices, and simplifies claim assertions by directly accessing array indices with conditional Validity checking.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A rabbit hops through schemas neat,
Where Sources, Claims, and Proofs now meet,
With foreign keys and constraints tight,
The database dance shines oh so bright!
Tests enabled, relationships bind,
A cleaner model, well-designed. 🌱

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: adding GORM-level foreign key constraints to models in the OpenAPI specification.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/gorm-sql-constarints

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 and usage tips.

@semmet95 semmet95 marked this pull request as ready for review May 27, 2026 15:36
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@pkg/domain/claim/claim_service_test.go`:
- Around line 265-269: The current validity check on updatedClaims allows both
entries to be false and still pass; change the test to assert that the two
Validity values are opposite so exactly one is true and the other false by
replacing the conditional branches that inspect updatedClaims[0].Validity and
updatedClaims[1].Validity with a definite assertion that
updatedClaims[0].Validity != updatedClaims[1].Validity (and optionally also
assert that at least one is true) to ensure the test fails when both are false;
locate the logic that reads updatedClaims[...] and updates Validity in
claim_service_test.go and tighten the assertion accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3b42b1fd-616a-44d4-9b08-5d609517fcff

📥 Commits

Reviewing files that changed from the base of the PR and between 52c937e and ac4d1ca.

📒 Files selected for processing (6)
  • api/source-score.yaml
  • pkg/api/server.gen.go
  • pkg/domain/claim/claim_service_test.go
  • pkg/domain/claim/claim_suite_test.go
  • pkg/domain/proof/proof_suite_test.go
  • pkg/domain/source/source_suite_test.go

Comment thread pkg/domain/claim/claim_service_test.go
@semmet95
Copy link
Copy Markdown
Contributor Author

@cubic-dev-ai

@cubic-dev-ai
Copy link
Copy Markdown

cubic-dev-ai Bot commented May 27, 2026

@cubic-dev-ai

@semmet95 I have started the AI code review. It will take a few minutes to complete.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread pkg/domain/claim/claim_service_test.go
Signed-off-by: Amit Singh <singhamitch@outlook.com>
@semmet95 semmet95 force-pushed the feat/gorm-sql-constarints branch from f40bf39 to b1b95bf Compare May 27, 2026 16:11
@semmet95 semmet95 merged commit 2cd1c5f into main May 27, 2026
4 checks passed
@semmet95 semmet95 deleted the feat/gorm-sql-constarints branch May 27, 2026 16:14
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.

1 participant