Skip to content

Commit 66b4fba

Browse files
posgres support
1 parent 2aef6ff commit 66b4fba

File tree

8 files changed

+1316
-1239
lines changed

8 files changed

+1316
-1239
lines changed

framework/configstore/config.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type ConfigStoreType string
1111
// ConfigStoreTypeSQLite is the type of config store for SQLite.
1212
const (
1313
ConfigStoreTypeSQLite ConfigStoreType = "sqlite"
14+
ConfigStoreTypePostgres ConfigStoreType = "postgres"
1415
)
1516

1617
// Config represents the configuration for the config store.
@@ -51,7 +52,12 @@ func (c *Config) UnmarshalJSON(data []byte) error {
5152
return fmt.Errorf("failed to unmarshal sqlite config: %w", err)
5253
}
5354
c.Config = &sqliteConfig
54-
55+
case ConfigStoreTypePostgres:
56+
var postgresConfig PostgresConfig
57+
if err := json.Unmarshal(temp.Config, &postgresConfig); err != nil {
58+
return fmt.Errorf("failed to unmarshal postgres config: %w", err)
59+
}
60+
c.Config = &postgresConfig
5561
default:
5662
return fmt.Errorf("unknown config store type: %s", temp.Type)
5763
}

framework/configstore/postgres.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package configstore
2+
3+
import (
4+
"context"
5+
6+
"github.com/maximhq/bifrost/core/schemas"
7+
"gorm.io/driver/postgres"
8+
"gorm.io/gorm"
9+
)
10+
11+
// PostgresConfig represents the configuration for a Postgres database.
12+
type PostgresConfig struct {
13+
DSN string `json:"dsn"`
14+
}
15+
16+
// newPostgresConfigStore creates a new Postgres config store.
17+
func newPostgresConfigStore(ctx context.Context, config *PostgresConfig, logger schemas.Logger) (ConfigStore, error) {
18+
db, err := gorm.Open(postgres.Open(config.DSN), &gorm.Config{})
19+
if err != nil {
20+
return nil, err
21+
}
22+
d := &RDBConfigStore{db: db, logger: logger}
23+
// Run migrations
24+
if err := triggerMigrations(ctx, db); err != nil {
25+
return nil, err
26+
}
27+
return d, nil
28+
}

0 commit comments

Comments
 (0)