BREAKING CHANGE: V2 of thr SDK #12

Merged
fenpaws merged 124 commits from develop/postgresql into main 2024-07-01 20:46:28 +00:00
Showing only changes of commit 57729359d2 - Show all commits

View File

@ -2,7 +2,6 @@ package database
import (
"context"
"database/sql"
"embed"
"fmt"
log2 "log"
@ -27,10 +26,9 @@ type postgresqlConnection struct {
debug bool
}
func NewPostgresqlConnection(debugOutput bool) OtterSpace {
func NewPostgresqlConnection() OtterSpace {
return &postgresqlConnection{
db: nil,
debug: debugOutput,
}
}
@ -45,13 +43,6 @@ func (p *postgresqlConnection) Connect(_ context.Context, config models.Database
dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=%s TimeZone=%s", config.Endpoint, config.Username, config.Password, config.Database, config.Port, localSSL, config.Timezone)
var err error
err = p.migrateDatabase(dsn)
if err != nil {
return err
}
log.Infof("OtterSpace: migration compleate")
dbLogger := logger2.New(log2.New(os.Stdout, "\r\n", log2.LstdFlags), logger2.Config{
SlowThreshold: 200 * time.Millisecond,
LogLevel: logger2.Warn,
@ -67,7 +58,14 @@ func (p *postgresqlConnection) Connect(_ context.Context, config models.Database
return err
}
log.Infof("OtterSpace: postgres connection established")
log.Infof("OtterSpace: database connection established")
err = p.migrateDatabase(db)
if err != nil {
return err
}
log.Infof("OtterSpace: migration compleate")
return nil
}
@ -148,11 +146,11 @@ func (p *postgresqlConnection) GetSourceByDomain(ctx context.Context, sourceDoma
return postgres.GetSourceByDomain(ctx, p.db, sourceDomain)
}
func (p *postgresqlConnection) migrateDatabase(connectionString string) error {
func (p *postgresqlConnection) migrateDatabase(dbPool *gorm.DB) error {
dialect := "postgres"
migrations := &migrate.EmbedFileSystemMigrationSource{FileSystem: embedMigrations, Root: "migrations"}
db, err := sql.Open(dialect, connectionString)
db, err := dbPool.DB()
if err != nil {
return fmt.Errorf("postgres migration: %v", err)
}