Skip to content

chore(goose): add function to determine if the database is up-to-date BED-9123 - #3099

Merged
sirisjo merged 4 commits into
mainfrom
BED-9123
Aug 6, 2026
Merged

chore(goose): add function to determine if the database is up-to-date BED-9123#3099
sirisjo merged 4 commits into
mainfrom
BED-9123

Conversation

@sirisjo

@sirisjo sirisjo commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Description

Adding a helper function to the Goose migration suite that checks if the database is using the goose_db_version table to track migrations or has any pending migrations.

Motivation and Context

Partially resolves BED-9123

We need to use this helper function in BHE.

How Has This Been Tested?

Integration tests added.

Screenshots (optional):

Types of changes

  • Chore (a change that does not modify the application functionality)

Checklist:

Summary by CodeRabbit

  • New Features

    • Added migration status checks to identify pending database updates and provide contextual errors for incomplete migration setups.
  • Tests

    • Added coverage for databases with missing, legacy, partially applied, and fully applied migration records.

@sirisjo sirisjo self-assigned this Aug 4, 2026
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 5b19f81a-3577-47b8-9236-d9e598b3441f

📥 Commits

Reviewing files that changed from the base of the PR and between 479debd and 2e75889.

📒 Files selected for processing (2)
  • cmd/api/src/database/migration/migration.go
  • cmd/api/src/test/integration/database.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • cmd/api/src/database/migration/migration.go
  • cmd/api/src/test/integration/database.go

📝 Walkthrough

Walkthrough

The migrator now creates and reuses a Goose provider. It detects pending migrations by checking legacy and Goose tables, then querying Goose migration status. Integration tests cover four database states.

Changes

Migration status detection

Layer / File(s) Summary
Goose provider initialization and integration wiring
cmd/api/src/database/migration/migration.go, cmd/api/src/database/migration/goose.go, cmd/api/src/test/integration/database.go, cmd/api/src/database/migration/goose_migration_integration_test.go
NewMigrator creates and stores a PostgreSQL Goose provider. Test setup and migration execution reuse the provider.
Pending migration checks and integration coverage
cmd/api/src/database/migration/goose.go, cmd/api/src/database/migration/goose_migration_integration_test.go
HasPendingMigrations checks migration table presence and Goose status. Integration tests cover absent, legacy-only, partial, and complete migration states.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested labels: dbmigration

Sequence Diagram(s)

sequenceDiagram
  participant Migrator
  participant PostgreSQL
  participant GooseProvider
  Migrator->>PostgreSQL: Check legacy and Goose migration tables
  PostgreSQL-->>Migrator: Return table presence
  Migrator->>GooseProvider: Query pending migrations
  GooseProvider-->>Migrator: Return migration status
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% 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
Title check ✅ Passed The title clearly identifies the Goose helper that determines whether the database is up to date and includes the related ticket.
Description check ✅ Passed The description covers the change, motivation, testing, change type, issue association, and checklist items.
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 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch BED-9123

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

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

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

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 `@cmd/api/src/test/integration/database.go`:
- Around line 165-167: Update the NewMigrator error branch in the database setup
flow to close both db and pool before returning the wrapped error, ensuring test
resources are released when migrator creation fails.
🪄 Autofix

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: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 18bd117c-825a-4627-a064-0c296ef13bf1

📥 Commits

Reviewing files that changed from the base of the PR and between ae91270 and 479debd.

📒 Files selected for processing (5)
  • cmd/api/src/database/db.go
  • cmd/api/src/database/migration/goose.go
  • cmd/api/src/database/migration/goose_migration_integration_test.go
  • cmd/api/src/database/migration/migration.go
  • cmd/api/src/test/integration/database.go
💤 Files with no reviewable changes (1)
  • cmd/api/src/database/db.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/api/src/database/migration/goose.go

Comment thread cmd/api/src/test/integration/database.go

@mistahj67 mistahj67 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.

Code LGTM and tested locally, no issues. 🚀

@sirisjo
sirisjo merged commit 31fe120 into main Aug 6, 2026
13 checks passed
@sirisjo
sirisjo deleted the BED-9123 branch August 6, 2026 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants