Skip to content

fix: migrations rerunning on every start for logstore - #4421

Merged
akshaydeo merged 2 commits into
devfrom
06-16-fix_migrations_rerunning_on_every_start_for_logstore
Jun 16, 2026
Merged

fix: migrations rerunning on every start for logstore#4421
akshaydeo merged 2 commits into
devfrom
06-16-fix_migrations_rerunning_on_every_start_for_logstore

Conversation

@danpiths

Copy link
Copy Markdown
Collaborator

Summary

This PR addresses a few minor correctness and noise issues: migration dialect
guards are moved inside the transaction callback so they are properly recorded
in the migrations table even when skipped, Postgres connection log lines are
demoted from Info to Debug to reduce log noise, the env label truncation limit
is increased, and a development label is added to the Python integration test
config.

Changes

  • Moved the db.Dialector.Name() != "postgres" early-return checks from outside
    the migrator setup into the Migrate callback for
    migrationSplitFilterDataMatView, migrationAddSafeJsonbFunction,
    migrationRecreateFilterUsersMatView,
    migrationRecreateFilterTeamBUMatViews, and
    migrationRecreateFilterCustomersMatView. This ensures non-Postgres
    environments still register the migration as applied rather than silently
    skipping it, preventing re-runs on future startups. The same guard was removed
    entirely from migrationRecreateMatViewsWithGovernanceColumns (the migrator
    itself handles the no-op).
  • Downgraded the Postgres connection target log lines in both configstore and
    logstore from Info to Debug to reduce routine startup noise.
  • Increased the truncateLabel character limit from 10 to 14 in the HTTP
    transport config loader to allow slightly longer labels without truncation.
  • Added "env_label": "Development" to the Python integration test config.

Type of change

  • Bug fix
  • Feature
  • Refactor
  • Documentation
  • Chore/CI

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations
  • Plugins
  • UI (React)
  • Docs

How to test

go test ./framework/configstore/... ./framework/logstore/... ./transports/bifrost-http/...

Verify that on a non-Postgres dialect, the previously skipped migrations are now
recorded as applied in the migrations table after startup. Confirm that Postgres
connection details no longer appear at the Info log level during startup.

Screenshots/Recordings

N/A

Breaking changes

  • Yes
  • No

Related issues

N/A

Security considerations

The Postgres connection log demotion to Debug reduces the chance of host, port,
and database name appearing in Info-level log aggregators, which is a minor
improvement for environments where Info logs are broadly exported.

Checklist

  • I read docs/contributing/README.md and followed the guidelines
  • I added/updated tests where appropriate
  • I updated documentation where needed
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

@danpiths
danpiths requested a review from akshaydeo June 16, 2026 04:48
@CLAassistant

CLAassistant commented Jun 16, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 2 committers have signed the CLA.

❌ danpiths
❌ akshaydeo
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: ac9ecd0a-a6c6-4c53-bbbe-289314fece3f

📥 Commits

Reviewing files that changed from the base of the PR and between c361ce6 and 37f1865.

📒 Files selected for processing (5)
  • framework/configstore/postgres.go
  • framework/logstore/migrations.go
  • framework/logstore/postgres.go
  • tests/integrations/python/config.json
  • transports/bifrost-http/lib/config.go
🚧 Files skipped from review as they are similar to previous changes (5)
  • framework/configstore/postgres.go
  • tests/integrations/python/config.json
  • framework/logstore/postgres.go
  • transports/bifrost-http/lib/config.go
  • framework/logstore/migrations.go

📝 Walkthrough

Summary by CodeRabbit

  • Chores
    • Reduced log verbosity for database connection target details.
    • Refined PostgreSQL-only migration handling to avoid unnecessary early exits and improve dialect behavior.
  • Configuration
    • Adjusted env_label truncation to cap at 14 characters.
  • Tests
    • Updated integration test configuration to include an env_label default set to “Development”.

Walkthrough

Two Postgres connection-target log statements are downgraded from Info to Debug. Six migration functions are refactored to unconditionally construct migration objects, moving the PostgreSQL dialect guard into the Migrate callback body. The EnvLabel truncation limit in LoadConfig is raised from 10 to 14 runes, and env_label: "Development" is added to the Python integration test config.

Changes

Postgres Framework Changes

Layer / File(s) Summary
Log verbosity downgrade: Info → Debug
framework/configstore/postgres.go, framework/logstore/postgres.go
Connection-target log calls (host/port/db/sslmode) changed from logger.Info to logger.Debug in both newPostgresConfigStore and newPostgresLogStore.
Migration dialect guards moved into Migrate callbacks
framework/logstore/migrations.go
Six migration functions (migrationRecreateMatViewsWithGovernanceColumns, migrationSplitFilterDataMatView, migrationAddSafeJsonbFunction, migrationRecreateFilterUsersMatView, migrationRecreateFilterTeamBUMatViews, migrationRecreateFilterCustomersMatView) now unconditionally construct their migration objects; the db.Dialector.Name() != "postgres" guard is relocated into the Migrate callback body.

EnvLabel Truncation and Test Config

Layer / File(s) Summary
EnvLabel truncation limit and test fixture
transports/bifrost-http/lib/config.go, tests/integrations/python/config.json
truncateLabel now truncates EnvLabel to 14 runes instead of 10. The Python integration test config gains a top-level env_label: "Development" field.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • maximhq/bifrost#4409: Touches the same newPostgresConfigStore and newPostgresLogStore startup logging paths that this PR downgrades from Info to Debug.
  • maximhq/bifrost#4416: Both PRs modify framework/logstore/migrations.go to refactor how migration dialect guards are structured and executed on PostgreSQL dialects.

Suggested reviewers

  • roroghost17

Poem

🐇 Hoppity-hop through the migration maze,
No more Info logs cluttering our days!
The dialect guards now live deep inside,
And EnvLabel grows — fourteen chars wide.
"Development" blooms in the Python test soil,
A rabbit at peace after minimal toil! 🌱

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The PR title directly addresses the main issue: fixing migrations rerunning on every start for logstore, which is the primary bug fix in this changeset.
Description check ✅ Passed The PR description comprehensively covers all required template sections including summary, detailed changes, type of change, affected areas, testing instructions, breaking changes assessment, and a completed checklist.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 06-16-fix_migrations_rerunning_on_every_start_for_logstore

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


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

@akshaydeo akshaydeo mentioned this pull request Jun 16, 2026
18 tasks
@danpiths
danpiths marked this pull request as ready for review June 16, 2026 04:49

danpiths commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai
coderabbitai Bot requested a review from roroghost17 June 16, 2026 04:50
@greptile-apps

greptile-apps Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5

Merge should wait for the schema contract to match the runtime config loader behavior.

The changed files are small and the migration/logging updates are straightforward, but the published config schema remains inconsistent with the new runtime label limit and can reject configs the application now accepts.

transports/config.schema.json should be updated to match transports/bifrost-http/lib/config.go.

T-Rex T-Rex Logs

What T-Rex did

  • The migration tests were run, showing that the base run had 55 migrations with 5 target migrations missing from the migrations table and the test failing, while the head run recorded 60 migrations with all 5 target migrations now present and a subsequent run produced no new rows and the test passed; a note mentions the 6th migration is not tested because it is not part of logstoreMigrationSteps.
  • The log level for the two target lines was downgraded from Info to Debug between the base and head commits for configstore and logstore, and both lines now appear as Debug in the head.

View all artifacts

T-Rex Ran code and verified through T-Rex

Reviews (3): Last reviewed commit: "Update config.go" | Re-trigger Greptile

Comment thread transports/bifrost-http/lib/config.go

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

🤖 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 `@tests/integrations/python/config.json`:
- Line 3: The env_label value in the config.json fixture exceeds the maximum
length constraint defined in the transport schema. The value "Development" is 11
characters, but transports/config.schema.json specifies maxLength of 10 for
env_label. Shorten the env_label value to 10 characters or fewer to align with
the schema constraint that serves as the source of truth for transport
configuration.

In `@transports/bifrost-http/lib/config.go`:
- Around line 889-893: The truncateLabel function in
transports/bifrost-http/lib/config.go has a logic error: it checks if the rune
length exceeds 10 but then truncates to 14 runes instead of 10. This contradicts
the transports/config.schema.json schema which enforces maxLength: 10 for
env_label as the authoritative source of truth. Fix the function by changing the
return statement to return only the first 10 runes (string(r[:10])) to align the
runtime behavior with the schema constraint.
- Around line 891-893: The truncation logic in the code has a boundary mismatch
that causes a panic. The condition checks if len(r) > 10 (meaning length is at
least 11), but then attempts to slice r[:14], which will panic when the actual
length is 11, 12, or 13. Fix this by changing the boundary check to len(r) > 14
to ensure the slice operation is safe, or alternatively by clamping the slice
index to the actual length of the rune slice using a minimum function before
accessing r[:14].
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 4b8b94f8-3fce-487f-9247-bd12689048bc

📥 Commits

Reviewing files that changed from the base of the PR and between ad39b19 and 0de9ff7.

📒 Files selected for processing (5)
  • framework/configstore/postgres.go
  • framework/logstore/migrations.go
  • framework/logstore/postgres.go
  • tests/integrations/python/config.json
  • transports/bifrost-http/lib/config.go

Comment thread tests/integrations/python/config.json
Comment thread transports/bifrost-http/lib/config.go
Comment thread transports/bifrost-http/lib/config.go Outdated
@danpiths
danpiths force-pushed the 06-16-fix_migrations_rerunning_on_every_start_for_logstore branch from c361ce6 to 37f1865 Compare June 16, 2026 10:58

akshaydeo commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Merge activity

  • Jun 16, 11:33 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jun 16, 11:34 AM UTC: @akshaydeo merged this pull request with Graphite.

@akshaydeo
akshaydeo merged commit 2a0639b into dev Jun 16, 2026
16 of 17 checks passed
@akshaydeo
akshaydeo deleted the 06-16-fix_migrations_rerunning_on_every_start_for_logstore branch June 16, 2026 11:34
Comment on lines +893 to +894
if len(r) > 14 {
return string(r[:14])

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.

P1 Update Schema Limit

The loader now accepts and truncates env_label at 14 runes, and this PR adds the 11-character value Development, but transports/config.schema.json still advertises and enforces maxLength: 10. Configs with labels from 11 to 14 characters can now load successfully at runtime but fail schema validation in tools or CI that use the published schema. Please update the schema description and maxLength to 14 with this runtime limit.

Rule Used: transports/config.schema.json is the source of tru... (source)

akhsaul pushed a commit to akhsaul/bifrost that referenced this pull request Aug 27, 2026
## Summary

This PR addresses a few minor correctness and noise issues: migration dialect
guards are moved inside the transaction callback so they are properly recorded
in the migrations table even when skipped, Postgres connection log lines are
demoted from Info to Debug to reduce log noise, the env label truncation limit
is increased, and a development label is added to the Python integration test
config.

## Changes

- Moved the `db.Dialector.Name() != "postgres"` early-return checks from outside
  the migrator setup into the `Migrate` callback for
  `migrationSplitFilterDataMatView`, `migrationAddSafeJsonbFunction`,
  `migrationRecreateFilterUsersMatView`,
  `migrationRecreateFilterTeamBUMatViews`, and
  `migrationRecreateFilterCustomersMatView`. This ensures non-Postgres
  environments still register the migration as applied rather than silently
  skipping it, preventing re-runs on future startups. The same guard was removed
  entirely from `migrationRecreateMatViewsWithGovernanceColumns` (the migrator
  itself handles the no-op).
- Downgraded the Postgres connection target log lines in both `configstore` and
  `logstore` from `Info` to `Debug` to reduce routine startup noise.
- Increased the `truncateLabel` character limit from 10 to 14 in the HTTP
  transport config loader to allow slightly longer labels without truncation.
- Added `"env_label": "Development"` to the Python integration test config.

## Type of change

- [x] Bug fix
- [ ] Feature
- [ ] Refactor
- [ ] Documentation
- [ ] Chore/CI

## Affected areas

- [x] Core (Go)
- [x] Transports (HTTP)
- [x] Providers/Integrations
- [ ] Plugins
- [ ] UI (React)
- [ ] Docs

## How to test

```sh
go test ./framework/configstore/... ./framework/logstore/... ./transports/bifrost-http/...
```

Verify that on a non-Postgres dialect, the previously skipped migrations are now
recorded as applied in the migrations table after startup. Confirm that Postgres
connection details no longer appear at the Info log level during startup.

## Screenshots/Recordings

N/A

## Breaking changes

- [ ] Yes
- [x] No

## Related issues

N/A

## Security considerations

The Postgres connection log demotion to Debug reduces the chance of host, port,
and database name appearing in Info-level log aggregators, which is a minor
improvement for environments where Info logs are broadly exported.

## Checklist

- [x] I read `docs/contributing/README.md` and followed the guidelines
- [x] I added/updated tests where appropriate
- [x] I updated documentation where needed
- [x] I verified builds succeed (Go and UI)
- [x] I verified the CI pipeline passes locally if applicable
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