Skip to content

Commit

Permalink
run postgres cases in new db
Browse files Browse the repository at this point in the history
  • Loading branch information
bcmmbaga committed May 9, 2024
1 parent 77ff626 commit be2a773
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
18 changes: 18 additions & 0 deletions management/server/sql_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package server
import (
"errors"
"fmt"
"math/rand"
"path/filepath"
"runtime"
"strings"
Expand Down Expand Up @@ -610,6 +611,14 @@ func NewSqliteStoreFromFileStore(fileStore *FileStore, dataDir string, metrics t

// NewPostgresqlStoreFromFileStore restores a store from FileStore and stores Postgres DB.
func NewPostgresqlStoreFromFileStore(fileStore *FileStore, dsn string, metrics telemetry.AppMetrics) (*SqlStore, error) {
dbName := "store_" + randString(10)
db, _ := gorm.Open(postgres.Open(dsn), &gorm.Config{})
result := db.Exec(fmt.Sprintf("CREATE DATABASE %s ENCODING = 'UTF8'", dbName))
if result.Error != nil {
return nil, result.Error
}

dsn = fmt.Sprintf("%s dbname=%s ", dsn, dbName)
store, err := NewPostgresqlStore(dsn, metrics)
if err != nil {
return nil, err
Expand All @@ -629,3 +638,12 @@ func NewPostgresqlStoreFromFileStore(fileStore *FileStore, dsn string, metrics t

return store, nil
}

func randString(n int) string {
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyz1234567890")
b := make([]rune, n)
for i := range b {
b[i] = letterRunes[rand.Intn(len(letterRunes))]
}
return string(b)
}
9 changes: 0 additions & 9 deletions management/server/sql_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -922,12 +922,3 @@ func TestPostgresql_GetUserByTokenID(t *testing.T) {
require.NoError(t, err)
require.Equal(t, id, user.PATs[id].ID)
}

func randString(n int) string {
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyz1234567890")
b := make([]rune, n)
for i := range b {
b[i] = letterRunes[rand.Intn(len(letterRunes))]
}
return string(b)
}

0 comments on commit be2a773

Please sign in to comment.