Skip to content

feat: add regenerated_at timestamp to PAT#1542

Merged
AmanGIT07 merged 2 commits into
mainfrom
feat/add-pat-recreated-at
Apr 15, 2026
Merged

feat: add regenerated_at timestamp to PAT#1542
AmanGIT07 merged 2 commits into
mainfrom
feat/add-pat-recreated-at

Conversation

@AmanGIT07
Copy link
Copy Markdown
Contributor

Summary

  • Add regenerated_at nullable timestamp to PATs — NULL on creation, set to NOW() on regeneration
  • Field added to all PAT API responses (create, get, update, regenerate, search, org admin search)
  • RQL in both user PAT list and org PAT search

Changes

  • New migration: ALTER TABLE user_pats ADD COLUMN regenerated_at TIMESTAMPTZ
  • Domain model, DB struct, repository Regenerate() method
  • Proto: PAT message (field 14) and OrganizationPAT message (field 8)
  • Both transform functions (transformPATToPB, transformAggregatedPATToPB)
  • RQL filter/sort support for both PAT list and org PAT search
  • Audit record for regeneration now uses regenerated_at as occurred_at timestamp

Test plan

  • go build ./... passes
  • All existing tests pass
  • regeneratedPAT test fixture updated with RegeneratedAt field
  • Create PAT → regenerated_at is null
  • Regenerate PAT → regenerated_at is set
  • Update PAT title → regenerated_at unchanged

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 15, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
frontier Ready Ready Preview, Comment Apr 15, 2026 9:41am

@AmanGIT07 AmanGIT07 changed the title feat: add recreated-at timestamp to PAT feat: add regenerated_at timestamp to PAT Apr 15, 2026
@AmanGIT07 AmanGIT07 enabled auto-merge (squash) April 15, 2026 09:12
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 15, 2026

Warning

Rate limit exceeded

@AmanGIT07 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 29 minutes and 15 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 29 minutes and 15 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, 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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6b51536f-46c1-4348-8ab1-f4f0f4ab4bd9

📥 Commits

Reviewing files that changed from the base of the PR and between 8a5d915 and d65229e.

📒 Files selected for processing (1)
  • internal/store/postgres/org_pats_repository.go
📝 Walkthrough

Walkthrough

The PR adds a RegeneratedAt timestamp field to personal access token (PAT) models across core aggregates, user PAT storage, database repositories, and API transformations. A database migration introduces the corresponding schema column, and the Proton dependency is updated to a new commit hash.

Changes

Cohort / File(s) Summary
Build Configuration
Makefile
Updated PROTON_COMMIT to new commit hash for protobuf dependency version.
Core Models
core/aggregates/orgpats/service.go, core/userpat/models/pat.go
Added nullable RegeneratedAt *time.Time field with RQL support to PAT aggregates and model definitions.
User PAT Service
core/userpat/service.go, core/userpat/service_test.go
Updated Regenerate method to use stored regeneration timestamp in audit records; test fixture now populates RegeneratedAt field.
Database Migrations
internal/store/postgres/migrations/20260415100000_user_pats_regenerated_at.*
Added TIMESTAMPTZ column regenerated_at to user_pats table with corresponding down-migration.
Database Layer
internal/store/postgres/userpat.go, internal/store/postgres/userpat_repository.go, internal/store/postgres/org_pats_repository.go
Extended database models, repositories, and queries to support mapping, filtering, sorting, and persisting the RegeneratedAt timestamp field.
API Transformations
internal/api/v1beta1connect/organization_pats.go, internal/api/v1beta1connect/user_pat.go
Added conditional protobuf timestamp mappings for RegeneratedAt field in API response transformations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • rohilsurana

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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.

@coveralls
Copy link
Copy Markdown

coveralls commented Apr 15, 2026

Coverage Report for CI Build 24447500367

Coverage increased (+0.003%) to 41.73%

Details

  • Coverage increased (+0.003%) from the base build.
  • Patch coverage: 9 uncovered changes across 4 files (28 of 37 lines covered, 75.68%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
internal/store/postgres/userpat_repository.go 3 0 0.0%
internal/api/v1beta1connect/organization_pats.go 3 1 33.33%
internal/api/v1beta1connect/user_pat.go 3 1 33.33%
internal/store/postgres/org_pats_repository.go 16 14 87.5%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 36640
Covered Lines: 15290
Line Coverage: 41.73%
Coverage Strength: 11.87 hits per line

💛 - Coveralls

Copy link
Copy Markdown
Contributor

@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: 2

🧹 Nitpick comments (1)
core/userpat/service.go (1)

206-209: Guard nullable RegeneratedAt before dereferencing.

Line 206 dereferences a pointer (*regenerated.RegeneratedAt) directly. Since RegeneratedAt is defined as nullable at the model and schema level, a nil value would panic the request. While the postgres Regenerate() implementation currently sets this field to time.Now().UTC(), the interface contract doesn't mandate non-nil values. Defensive nil-checking is consistent with how the codebase handles this field elsewhere (see internal/api/v1beta1connect/organization_pats.go:84 and user_pat.go:307).

Suggested hardening
-	if err := s.createAuditRecord(ctx, pkgAuditRecord.PATRegeneratedEvent, regenerated, *regenerated.RegeneratedAt, map[string]any{
+	occurredAt := time.Now().UTC()
+	if regenerated.RegeneratedAt != nil {
+		occurredAt = *regenerated.RegeneratedAt
+	}
+	if err := s.createAuditRecord(ctx, pkgAuditRecord.PATRegeneratedEvent, regenerated, occurredAt, map[string]any{
 		"expires_at":     regenerated.ExpiresAt,
 		"old_expires_at": oldExpiresAt,
 	}); err != nil {

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d9093175-4e6c-4961-bd08-71f22b91b2e2

📥 Commits

Reviewing files that changed from the base of the PR and between 08d63db and 8a5d915.

⛔ Files ignored due to path filters (2)
  • proto/v1beta1/admin.pb.go is excluded by !**/*.pb.go, !proto/**
  • proto/v1beta1/models.pb.go is excluded by !**/*.pb.go, !proto/**
📒 Files selected for processing (12)
  • Makefile
  • core/aggregates/orgpats/service.go
  • core/userpat/models/pat.go
  • core/userpat/service.go
  • core/userpat/service_test.go
  • internal/api/v1beta1connect/organization_pats.go
  • internal/api/v1beta1connect/user_pat.go
  • internal/store/postgres/migrations/20260415100000_user_pats_regenerated_at.down.sql
  • internal/store/postgres/migrations/20260415100000_user_pats_regenerated_at.up.sql
  • internal/store/postgres/org_pats_repository.go
  • internal/store/postgres/userpat.go
  • internal/store/postgres/userpat_repository.go

Comment thread internal/store/postgres/org_pats_repository.go
Comment thread internal/store/postgres/org_pats_repository.go
@AmanGIT07 AmanGIT07 merged commit fd77b87 into main Apr 15, 2026
8 checks passed
@AmanGIT07 AmanGIT07 deleted the feat/add-pat-recreated-at branch April 15, 2026 09:50
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.

3 participants