Skip to content

Commit 3d59583

Browse files
TejasGhattePratham-Mishra04
authored andcommitted
feat: added migrator to log store
1 parent fff112b commit 3d59583

File tree

29 files changed

+173
-48
lines changed

29 files changed

+173
-48
lines changed

core/changelog.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<!-- The pattern we follow here is to keep the changelog for the latest version -->
22
<!-- Old changelogs are automatically attached to the GitHub releases -->
33

4-
- Feat: Stream token latency sent back in extra fields.
5-
- Feat: Plugin interface extended with TransportInterceptor method.
6-
- Feat: Add Anthropic thinking parameter
7-
- Feat: Add Custom key selector logic and send back request latency in extra fields.
8-
- Bug: Fallbacks not working occasionally.
4+
- Feat: Responses streaming added across all providers.
5+
- Fix: Bedrock chat streaming decoding fixes.
6+
- Feat: Added raw response support for all streaming requests.

core/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.2.5
1+
1.2.6

docs/changelogs/v1.3.0-prerelease6.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: "v1.3.0-prerelease6 changelog"
44
---
55
<Update label="Bifrost(HTTP)" description="v1.3.0-prerelease6">
66

7-
- Upgrade dependency: core to 1.2.5 and framework to 1.1.5
7+
- Upgrade dependency: core to 1.2.6 and framework to 1.1.6
88
- Feat: Added Anthropic thinking parameter in responses API.
99
- Feat: Added Anthropic text completion integration support.
1010
- Fix: Extra fields sent back in streaming responses.
@@ -37,37 +37,37 @@ description: "v1.3.0-prerelease6 changelog"
3737
</Update>
3838
<Update label="jsonparser" description="v1.3.0-prerelease6">
3939

40-
- Upgrade dependency: core to 1.2.5 and framework to 1.1.5
40+
- Upgrade dependency: core to 1.2.6 and framework to 1.1.6
4141

4242
</Update>
4343
<Update label="logging" description="v1.3.0-prerelease6">
4444

45-
- Upgrade dependency: core to 1.2.5 and framework to 1.1.5
45+
- Upgrade dependency: core to 1.2.6 and framework to 1.1.6
4646

4747
</Update>
4848
<Update label="maxim" description="v1.3.0-prerelease6">
4949

50-
- Upgrade dependency: core to 1.2.5 and framework to 1.1.5
50+
- Upgrade dependency: core to 1.2.6 and framework to 1.1.6
5151

5252
</Update>
5353
<Update label="mocker" description="v1.3.0-prerelease6">
5454

55-
- Upgrade dependency: core to 1.2.5 and framework to 1.1.5
55+
- Upgrade dependency: core to 1.2.6 and framework to 1.1.6
5656

5757
</Update>
5858
<Update label="otel" description="v1.3.0-prerelease6">
5959

60-
- Upgrade dependency: core to 1.2.5 and framework to 1.1.5
60+
- Upgrade dependency: core to 1.2.6 and framework to 1.1.6
6161

6262
</Update>
6363
<Update label="semanticcache" description="v1.3.0-prerelease6">
6464

65-
- Upgrade dependency: core to 1.2.5 and framework to 1.1.5
65+
- Upgrade dependency: core to 1.2.6 and framework to 1.1.6
6666

6767
</Update>
6868
<Update label="telemetry" description="v1.3.0-prerelease6">
6969

70-
- Upgrade dependency: core to 1.2.5 and framework to 1.1.5
70+
- Upgrade dependency: core to 1.2.6 and framework to 1.1.6
7171
- Feat: Added First Token and Inter Token latency metrics for streaming requests.
7272

7373
</Update>

framework/changelog.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!-- The pattern we follow here is to keep the changelog for the latest version -->
22
<!-- Old changelogs are automatically attached to the GitHub releases -->
33

4-
- Upgrade dependency: core to 1.2.5
5-
- Feat: User table added to config store.
4+
- Upgrade dependency: core to 1.2.6
5+
- Feat: Moved the migrator package to a more general location and added database migrations for the logstore to standardize object type values.

framework/configstore/migrations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"fmt"
66

7-
"github.com/maximhq/bifrost/framework/configstore/migrator"
7+
"github.com/maximhq/bifrost/framework/migrator"
88
"gorm.io/gorm"
99
)
1010

framework/configstore/rdb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"fmt"
88

99
"github.com/maximhq/bifrost/core/schemas"
10-
"github.com/maximhq/bifrost/framework/configstore/migrator"
10+
"github.com/maximhq/bifrost/framework/migrator"
1111
"github.com/maximhq/bifrost/framework/logstore"
1212
"github.com/maximhq/bifrost/framework/vectorstore"
1313
"gorm.io/gorm"

framework/configstore/store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"fmt"
77

88
"github.com/maximhq/bifrost/core/schemas"
9-
"github.com/maximhq/bifrost/framework/configstore/migrator"
9+
"github.com/maximhq/bifrost/framework/migrator"
1010
"github.com/maximhq/bifrost/framework/logstore"
1111
"github.com/maximhq/bifrost/framework/vectorstore"
1212
"gorm.io/gorm"

framework/logstore/migrations.go

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
package logstore
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/maximhq/bifrost/framework/migrator"
8+
"gorm.io/gorm"
9+
)
10+
11+
// Migrate performs the necessary database migrations.
12+
func triggerMigrations(ctx context.Context, db *gorm.DB) error {
13+
if err := migrationInit(ctx, db); err != nil {
14+
return err
15+
}
16+
if err := migrationUpdateObjectColumnValues(ctx, db); err != nil {
17+
return err
18+
}
19+
20+
return nil
21+
}
22+
23+
// migrationInit is the first migration
24+
func migrationInit(ctx context.Context, db *gorm.DB) error {
25+
m := migrator.New(db, migrator.DefaultOptions, []*migrator.Migration{{
26+
ID: "init",
27+
Migrate: func(tx *gorm.DB) error {
28+
tx = tx.WithContext(ctx)
29+
migrator := tx.Migrator()
30+
if !migrator.HasTable(&Log{}) {
31+
if err := migrator.CreateTable(&Log{}); err != nil {
32+
return err
33+
}
34+
}
35+
36+
return nil
37+
},
38+
Rollback: func(tx *gorm.DB) error {
39+
tx = tx.WithContext(ctx)
40+
migrator := tx.Migrator()
41+
// Drop children first, then parents (adjust if your actual FKs differ)
42+
if err := migrator.DropTable(&Log{}); err != nil {
43+
return err
44+
}
45+
return nil
46+
},
47+
}})
48+
err := m.Migrate()
49+
if err != nil {
50+
return fmt.Errorf("error while running db migration: %s", err.Error())
51+
}
52+
return nil
53+
}
54+
55+
// migrationUpdateObjectColumnValues updates the object column values from old format to new format
56+
func migrationUpdateObjectColumnValues(ctx context.Context, db *gorm.DB) error {
57+
m := migrator.New(db, migrator.DefaultOptions, []*migrator.Migration{{
58+
ID: "update_object_column_values",
59+
Migrate: func(tx *gorm.DB) error {
60+
tx = tx.WithContext(ctx)
61+
62+
updateSQL := `
63+
UPDATE logs
64+
SET object_type = CASE object_type
65+
WHEN 'chat.completion' THEN 'chat_completion'
66+
WHEN 'text.completion' THEN 'text_completion'
67+
WHEN 'list' THEN 'embedding'
68+
WHEN 'audio.speech' THEN 'speech'
69+
WHEN 'audio.transcription' THEN 'transcription'
70+
WHEN 'chat.completion.chunk' THEN 'chat_completion_stream'
71+
WHEN 'audio.speech.chunk' THEN 'speech_stream'
72+
WHEN 'audio.transcription.chunk' THEN 'transcription_stream'
73+
WHEN 'response' THEN 'responses'
74+
WHEN 'response.completion.chunk' THEN 'responses_stream'
75+
ELSE object_type
76+
END
77+
WHERE object_type IN (
78+
'chat.completion', 'text.completion', 'list',
79+
'audio.speech', 'audio.transcription', 'chat.completion.chunk',
80+
'audio.speech.chunk', 'audio.transcription.chunk',
81+
'response', 'response.completion.chunk'
82+
)`
83+
84+
result := tx.Exec(updateSQL)
85+
if result.Error != nil {
86+
return fmt.Errorf("failed to update object_type values: %w", result.Error)
87+
}
88+
89+
return nil
90+
},
91+
Rollback: func(tx *gorm.DB) error {
92+
tx = tx.WithContext(ctx)
93+
94+
// Use a single CASE statement for efficient bulk rollback
95+
rollbackSQL := `
96+
UPDATE logs
97+
SET object_type = CASE object_type
98+
WHEN 'chat_completion' THEN 'chat.completion'
99+
WHEN 'text_completion' THEN 'text.completion'
100+
WHEN 'embedding' THEN 'list'
101+
WHEN 'speech' THEN 'audio.speech'
102+
WHEN 'transcription' THEN 'audio.transcription'
103+
WHEN 'chat_completion_stream' THEN 'chat.completion.chunk'
104+
WHEN 'speech_stream' THEN 'audio.speech.chunk'
105+
WHEN 'transcription_stream' THEN 'audio.transcription.chunk'
106+
WHEN 'responses' THEN 'response'
107+
WHEN 'responses_stream' THEN 'response.completion.chunk'
108+
ELSE object_type
109+
END
110+
WHERE object_type IN (
111+
'chat_completion', 'text_completion', 'embedding', 'speech',
112+
'transcription', 'chat_completion_stream', 'speech_stream',
113+
'transcription_stream', 'responses', 'responses_stream'
114+
)`
115+
116+
result := tx.Exec(rollbackSQL)
117+
if result.Error != nil {
118+
return fmt.Errorf("failed to rollback object_type values: %w", result.Error)
119+
}
120+
121+
return nil
122+
},
123+
}})
124+
125+
err := m.Migrate()
126+
if err != nil {
127+
return fmt.Errorf("error while running object column migration: %s", err.Error())
128+
}
129+
return nil
130+
}

framework/logstore/sqlite.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ func newSqliteLogStore(ctx context.Context, config *SQLiteConfig, logger schemas
2222
if err != nil {
2323
return nil, err
2424
}
25-
if err := db.WithContext(ctx).AutoMigrate(&Log{}); err != nil {
25+
// Run migrations
26+
if err := triggerMigrations(ctx, db); err != nil {
2627
return nil, err
2728
}
2829
return &RDBLogStore{db: db, logger: logger}, nil
File renamed without changes.

0 commit comments

Comments
 (0)