Skip to content

RHINENG-25900: grant permissions after pg_repack recreate - #2165

Merged
MichaelMraka merged 1 commit into
RedHatInsights:masterfrom
MichaelMraka:pr2
Apr 20, 2026
Merged

MichaelMraka merged 1 commit into
RedHatInsights:masterfrom
MichaelMraka:pr2

Conversation

@MichaelMraka

@MichaelMraka MichaelMraka commented Apr 20, 2026

Copy link
Copy Markdown
Collaborator

Secure Coding Practices Checklist GitHub Link

Secure Coding Checklist

  • Input Validation
  • Output Encoding
  • Authentication and Password Management
  • Session Management
  • Access Control
  • Cryptographic Practices
  • Error Handling and Logging
  • Data Protection
  • Communication Security
  • System Configuration
  • Database Security
  • File Management
  • Memory Management
  • General Coding Practices

Summary by Sourcery

Update the pg_repack recreation endpoint to also restore required permissions after recreating the extension.

Bug Fixes:

  • Grant usage on the repack schema to the vmaas_sync role after recreating the pg_repack extension to restore necessary permissions.

Enhancements:

  • Execute the pg_repack drop, create, and permission grant statements as a single ordered sequence in the recreation handler.

@MichaelMraka
MichaelMraka requested a review from a team as a code owner April 20, 2026 08:39
@sourcery-ai

sourcery-ai Bot commented Apr 20, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates the pg_repack recreation handler to run a small sequence of SQL statements (drop, create, then grant permissions) in order, ensuring the vmaas_sync role regains necessary privileges after the extension is recreated.

File-Level Changes

Change Details Files
Refactor pg_repack recreation logic to run a sequence of SQL statements and grant schema usage to vmaas_sync after recreating the extension.
  • Replace two separate Exec calls with a slice of SQL commands executed sequentially in a loop
  • Include DROP EXTENSION, CREATE EXTENSION, and GRANT USAGE ON SCHEMA repack TO vmaas_sync in the execution sequence
  • Reuse the same error-handling pattern for each SQL statement, returning HTTP 500 on any failure and 200 OK only if all statements succeed
turnpike/controllers/database.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • Consider executing the runSequence statements inside a single database transaction so that a failure in one query doesn’t leave the database in a partially updated state.
  • It may be helpful to include the failing SQL statement (or a short label for it) in the error response to make operational debugging easier when one of the sequence steps fails.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider executing the `runSequence` statements inside a single database transaction so that a failure in one query doesn’t leave the database in a partially updated state.
- It may be helpful to include the failing SQL statement (or a short label for it) in the error response to make operational debugging easier when one of the sequence steps fails.

## Individual Comments

### Comment 1
<location path="turnpike/controllers/database.go" line_range="32-37" />
<code_context>
 	}
-	if err := database.DB.Exec("CREATE EXTENSION pg_repack").Error; err != nil {
-		c.JSON(http.StatusInternalServerError, gin.H{"err": err.Error()})
+	for _, query := range runSequence {
+		if err := database.DB.Exec(query).Error; err != nil {
+			c.JSON(http.StatusInternalServerError, gin.H{"err": err.Error()})
+			return
+		}
</code_context>
<issue_to_address>
**suggestion:** Improve error reporting by indicating which SQL statement in the sequence failed.

As written, the response only returns the raw DB error, which may not make it obvious which statement in `runSequence` failed. Returning the failing query (or a simple label/index for it) alongside the error would significantly aid debugging while preserving the existing control flow.

```suggestion
	for index, query := range runSequence {
		if err := database.DB.Exec(query).Error; err != nil {
			c.JSON(http.StatusInternalServerError, gin.H{
				"err":         err.Error(),
				"query":       query,
				"query_index": index,
			})
			return
		}
	}
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread turnpike/controllers/database.go
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.07%. Comparing base (31f4ea7) to head (1d2600f).
⚠️ Report is 8 commits behind head on master.

Files with missing lines Patch % Lines
turnpike/controllers/database.go 0.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2165      +/-   ##
==========================================
- Coverage   59.13%   59.07%   -0.06%     
==========================================
  Files         134      134              
  Lines        8738     8741       +3     
==========================================
- Hits         5167     5164       -3     
- Misses       3028     3034       +6     
  Partials      543      543              
Flag Coverage Δ
unittests 59.07% <0.00%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TenSt TenSt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm

@TenSt TenSt self-assigned this Apr 20, 2026
@MichaelMraka
MichaelMraka merged commit 96b44fe into RedHatInsights:master Apr 20, 2026
8 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.

3 participants