-
Notifications
You must be signed in to change notification settings - Fork 132
feat: added migrator to log store #612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,6 @@ | ||
| <!-- The pattern we follow here is to keep the changelog for the latest version --> | ||
| <!-- Old changelogs are automatically attached to the GitHub releases --> | ||
|
|
||
| - Feat: Stream token latency sent back in extra fields. | ||
| - Feat: Plugin interface extended with TransportInterceptor method. | ||
| - Feat: Add Anthropic thinking parameter | ||
| - Feat: Add Custom key selector logic and send back request latency in extra fields. | ||
| - Bug: Fallbacks not working occasionally. | ||
| - Feat: Responses streaming added across all providers. | ||
| - Fix: Bedrock chat streaming decoding fixes. | ||
| - Feat: Added raw response support for all streaming requests. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 1.2.5 | ||
| 1.2.6 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| <!-- The pattern we follow here is to keep the changelog for the latest version --> | ||
| <!-- Old changelogs are automatically attached to the GitHub releases --> | ||
|
|
||
| - Upgrade dependency: core to 1.2.5 | ||
| - Feat: User table added to config store. | ||
| - Upgrade dependency: core to 1.2.6 | ||
| - Feat: Moved the migrator package to a more general location and added database migrations for the logstore to standardize object type values. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| package logstore | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/maximhq/bifrost/framework/migrator" | ||
| "gorm.io/gorm" | ||
| ) | ||
|
|
||
| // Migrate performs the necessary database migrations. | ||
| func triggerMigrations(ctx context.Context, db *gorm.DB) error { | ||
| if err := migrationInit(ctx, db); err != nil { | ||
| return err | ||
| } | ||
| if err := migrationUpdateObjectColumnValues(ctx, db); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // migrationInit is the first migration | ||
| func migrationInit(ctx context.Context, db *gorm.DB) error { | ||
| m := migrator.New(db, migrator.DefaultOptions, []*migrator.Migration{{ | ||
| ID: "logs_init", | ||
| Migrate: func(tx *gorm.DB) error { | ||
| tx = tx.WithContext(ctx) | ||
| migrator := tx.Migrator() | ||
| if !migrator.HasTable(&Log{}) { | ||
| if err := migrator.CreateTable(&Log{}); err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| }, | ||
| Rollback: func(tx *gorm.DB) error { | ||
| tx = tx.WithContext(ctx) | ||
| migrator := tx.Migrator() | ||
| // Drop children first, then parents (adjust if your actual FKs differ) | ||
| if err := migrator.DropTable(&Log{}); err != nil { | ||
| return err | ||
| } | ||
| return nil | ||
| }, | ||
TejasGhatte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }}) | ||
| err := m.Migrate() | ||
| if err != nil { | ||
| return fmt.Errorf("error while running db migration: %s", err.Error()) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // migrationUpdateObjectColumnValues updates the object column values from old format to new format | ||
| func migrationUpdateObjectColumnValues(ctx context.Context, db *gorm.DB) error { | ||
| opts := *migrator.DefaultOptions | ||
| opts.UseTransaction = true | ||
| m := migrator.New(db, &opts, []*migrator.Migration{{ | ||
| ID: "logs_init_update_object_column_values", | ||
| Migrate: func(tx *gorm.DB) error { | ||
| tx = tx.WithContext(ctx) | ||
|
|
||
| updateSQL := ` | ||
| UPDATE logs | ||
| SET object_type = CASE object_type | ||
| WHEN 'chat.completion' THEN 'chat_completion' | ||
| WHEN 'text.completion' THEN 'text_completion' | ||
| WHEN 'list' THEN 'embedding' | ||
| WHEN 'audio.speech' THEN 'speech' | ||
| WHEN 'audio.transcription' THEN 'transcription' | ||
| WHEN 'chat.completion.chunk' THEN 'chat_completion_stream' | ||
| WHEN 'audio.speech.chunk' THEN 'speech_stream' | ||
| WHEN 'audio.transcription.chunk' THEN 'transcription_stream' | ||
| WHEN 'response' THEN 'responses' | ||
| WHEN 'response.completion.chunk' THEN 'responses_stream' | ||
| ELSE object_type | ||
| END | ||
| WHERE object_type IN ( | ||
| 'chat.completion', 'text.completion', 'list', | ||
| 'audio.speech', 'audio.transcription', 'chat.completion.chunk', | ||
| 'audio.speech.chunk', 'audio.transcription.chunk', | ||
| 'response', 'response.completion.chunk' | ||
| )` | ||
|
|
||
| result := tx.Exec(updateSQL) | ||
| if result.Error != nil { | ||
| return fmt.Errorf("failed to update object_type values: %w", result.Error) | ||
| } | ||
|
|
||
| return nil | ||
| }, | ||
| Rollback: func(tx *gorm.DB) error { | ||
| tx = tx.WithContext(ctx) | ||
|
|
||
| // Use a single CASE statement for efficient bulk rollback | ||
| rollbackSQL := ` | ||
| UPDATE logs | ||
| SET object_type = CASE object_type | ||
| WHEN 'chat_completion' THEN 'chat.completion' | ||
| WHEN 'text_completion' THEN 'text.completion' | ||
| WHEN 'embedding' THEN 'list' | ||
| WHEN 'speech' THEN 'audio.speech' | ||
| WHEN 'transcription' THEN 'audio.transcription' | ||
| WHEN 'chat_completion_stream' THEN 'chat.completion.chunk' | ||
| WHEN 'speech_stream' THEN 'audio.speech.chunk' | ||
| WHEN 'transcription_stream' THEN 'audio.transcription.chunk' | ||
| WHEN 'responses' THEN 'response' | ||
| WHEN 'responses_stream' THEN 'response.completion.chunk' | ||
| ELSE object_type | ||
| END | ||
| WHERE object_type IN ( | ||
| 'chat_completion', 'text_completion', 'embedding', 'speech', | ||
| 'transcription', 'chat_completion_stream', 'speech_stream', | ||
| 'transcription_stream', 'responses', 'responses_stream' | ||
| )` | ||
|
|
||
TejasGhatte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| result := tx.Exec(rollbackSQL) | ||
| if result.Error != nil { | ||
| return fmt.Errorf("failed to rollback object_type values: %w", result.Error) | ||
| } | ||
|
|
||
| return nil | ||
| }, | ||
| }}) | ||
|
|
||
| err := m.Migrate() | ||
| if err != nil { | ||
| return fmt.Errorf("error while running object column migration: %s", err.Error()) | ||
| } | ||
| return nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 1.1.5 | ||
| 1.1.6 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| <!-- The pattern we follow here is to keep the changelog for the latest version --> | ||
| <!-- Old changelogs are automatically attached to the GitHub releases --> | ||
|
|
||
| - Chore: using core 1.2.5 and framework 1.1.5 | ||
| - Feat: Added provider routing TransportInterceptor. | ||
| - Chore: using core 1.2.6 and framework 1.1.6 | ||
Pratham-Mishra04 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 1.3.5 | ||
| 1.3.6 | ||
TejasGhatte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| <!-- The pattern we follow here is to keep the changelog for the latest version --> | ||
| <!-- Old changelogs are automatically attached to the GitHub releases --> | ||
|
|
||
| - Upgrade dependency: core to 1.2.5 and framework to 1.1.5 | ||
| - Upgrade dependency: core to 1.2.6 and framework to 1.1.6 | ||
Pratham-Mishra04 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 1.3.5 | ||
| 1.3.6 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainVerify the necessity of this version bump. The patch version bump from 1.3.5 to 1.3.6 appears unrelated to the main PR changes (migrator refactoring and logstore migrations). While the AI summary mentions this is part of broader version bumps across modules, it's unclear whether the jsonparser plugin has any actual changes that warrant a version bump. Please confirm:
🏁 Script executed: #!/bin/bash
# Description: Check for actual code changes in the jsonparser plugin and look for changelog updates
# Search for jsonparser plugin files to see if there are code changes
fd -e go -p 'plugins/jsonparser' --exec echo "File: {}"
# Look for changelog or version-related documentation
fd -e md -p 'plugins/jsonparser' | head -20
# Check if other files reference the jsonparser version
rg -n 'jsonparser.*1\.3\.[56]'Length of output: 108 🏁 Script executed: #!/bin/bash
# Verify changelog entry for version 1.3.6
grep -nE '^##\s*1\.3\.6' plugins/jsonparser/changelog.md || echo "No entry for 1.3.6"
# Show diff for plugin source files to see actual changes
git diff origin/main...HEAD -- plugins/jsonparser/main.go plugins/jsonparser/plugin_test.goLength of output: 18 Document or revert jsonparser patch bump The patch bump to 1.3.6 in plugins/jsonparser/version has no corresponding code changes and no entry in plugins/jsonparser/changelog.md. Add release notes for v1.3.6 or revert this bump. 🤖 Prompt for AI Agents
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainVerify the necessity of this version bump. The jsonparser plugin version has been incremented to 1.3.6, but the PR objectives and summary indicate no functional changes to the jsonparser plugin itself. Since this PR focuses on migrator and logstore changes, please confirm:
Run the following script to check for dependency updates and changelog entries: 🏁 Script executed: #!/bin/bash
# Description: Verify jsonparser dependencies and changelog for version 1.3.6
# Check go.mod for core/framework dependencies
if [ -f "plugins/jsonparser/go.mod" ]; then
echo "=== jsonparser dependencies ==="
rg -A 2 'github.com/maximhq/bifrost/(core|framework)' plugins/jsonparser/go.mod
fi
# Check for changelog entries
echo "=== Checking for changelog ==="
fd -t f 'CHANGELOG|changelog|HISTORY|history' plugins/jsonparser/
# Check for version references in plugin files
echo "=== Version references in jsonparser ==="
rg -n '1\.3\.[56]' plugins/jsonparser/Length of output: 228 🏁 Script executed: #!/bin/bash
# Verify changelog entry for version 1.3.6 in jsonparser plugin
echo "=== Changelog entries around 1.3.6 ==="
rg -n '1\.3\.6' -C2 plugins/jsonparser/changelog.md || echo "No entries found for 1.3.6"Length of output: 65 Add missing changelog entry and update dependency
🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| <!-- The pattern we follow here is to keep the changelog for the latest version --> | ||
| <!-- Old changelogs are automatically attached to the GitHub releases --> | ||
|
|
||
| - Upgrade dependency: core to 1.2.5 and framework to 1.1.5 | ||
| - Upgrade dependency: core to 1.2.6 and framework to 1.1.6 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 1.3.5 | ||
| 1.3.6 | ||
TejasGhatte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| <!-- The pattern we follow here is to keep the changelog for the latest version --> | ||
| <!-- Old changelogs are automatically attached to the GitHub releases --> | ||
|
|
||
| - Upgrade dependency: core to 1.2.5 and framework to 1.1.5 | ||
| - Upgrade dependency: core to 1.2.6 and framework to 1.1.6 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 1.4.5 | ||
| 1.4.6 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| <!-- The pattern we follow here is to keep the changelog for the latest version --> | ||
| <!-- Old changelogs are automatically attached to the GitHub releases --> | ||
|
|
||
| - Upgrade dependency: core to 1.2.5 and framework to 1.1.5 | ||
| - Upgrade dependency: core to 1.2.6 and framework to 1.1.6 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 1.3.5 | ||
| 1.3.6 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| <!-- The pattern we follow here is to keep the changelog for the latest version --> | ||
| <!-- Old changelogs are automatically attached to the GitHub releases --> | ||
|
|
||
| - Upgrade dependency: core to 1.2.5 and framework to 1.1.5 | ||
| - Upgrade dependency: core to 1.2.6 and framework to 1.1.6 | ||
Pratham-Mishra04 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 1.0.5 | ||
| 1.0.6 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| <!-- The pattern we follow here is to keep the changelog for the latest version --> | ||
| <!-- Old changelogs are automatically attached to the GitHub releases --> | ||
|
|
||
| - Upgrade dependency: core to 1.2.5 and framework to 1.1.5 | ||
| - Upgrade dependency: core to 1.2.6 and framework to 1.1.6 | ||
TejasGhatte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 1.3.5 | ||
| 1.3.6 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| <!-- The pattern we follow here is to keep the changelog for the latest version --> | ||
| <!-- Old changelogs are automatically attached to the GitHub releases --> | ||
|
|
||
| - Upgrade dependency: core to 1.2.5 and framework to 1.1.5 | ||
| - Feat: Added First Token and Inter Token latency metrics for streaming requests. | ||
| - Upgrade dependency: core to 1.2.6 and framework to 1.1.6 | ||
| - Fix: Removed last token's accumulated latency from inter token latency metric. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 1.3.5 | ||
| 1.3.6 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,8 @@ | ||
| <!-- The pattern we follow here is to keep the changelog for the latest version --> | ||
| <!-- Old changelogs are automatically attached to the GitHub releases --> | ||
|
|
||
| - Upgrade dependency: core to 1.2.5 and framework to 1.1.5 | ||
| - Feat: Added Anthropic thinking parameter in responses API. | ||
| - Feat: Added Anthropic text completion integration support. | ||
| - Fix: Extra fields sent back in streaming responses. | ||
| - Feat: Latency for all request types (with inter token latency for streaming requests) sent back in Extra fields. | ||
| - Feat: UI websocket implementation generalized. | ||
| - Feat: TokenInterceptor interface added to plugins. | ||
| - Fix: Middlewares added to integrations route. | ||
| - Upgrade dependency: core to 1.2.6 and framework to 1.1.6 | ||
| - Added Responses streaming across all providers. | ||
| - Fixed bedrock chat streaming decoding issues. | ||
| - Added raw response support for all streaming requests. | ||
| - Removed last token's accumulated latency from inter token latency metric. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 1.3.0-prerelease6 | ||
| 1.3.0-prerelease7 |
Uh oh!
There was an error while loading. Please reload this page.