Skip to content

Commit

Permalink
feat(backend): add postgres initialization (#9798)
Browse files Browse the repository at this point in the history
* add postgres initialization

* remove load balancer

* go mod tidy

* update license

* license update for viewer

* (test) disable controller license check

* (test) disable persistence agence licence check

* (test) disable scheduled workflow license check

* (test) disable cacheserver license check

* fix db config location

* fix mysql support

* test

* test

* no long set host address

* address comments

* address comments and enable license check

* format

* remove extra blank line

* update licenses

* cache server license

* address comments

* centralize error message

* remove pv in postgres deployment
  • Loading branch information
Linchin authored Aug 10, 2023
1 parent b350ac4 commit e1f0c01
Show file tree
Hide file tree
Showing 20 changed files with 428 additions and 151 deletions.
36 changes: 34 additions & 2 deletions backend/src/apiserver/client/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,22 @@
package client

import (
"bytes"
"fmt"

"github.com/go-sql-driver/mysql"
)

func CreateMySQLConfig(user, password string, mysqlServiceHost string,
mysqlServicePort string, dbName string, mysqlGroupConcatMaxLen string, mysqlExtraParams map[string]string,
const (
MYSQL_TEXT_FORMAT string = "longtext not null"
MYSQL_EXIST_ERROR string = "database exists"

PGX_TEXT_FORMAT string = "text"
PGX_EXIST_ERROR string = "already exists"
)

func CreateMySQLConfig(user, password, mysqlServiceHost, mysqlServicePort,
dbName, mysqlGroupConcatMaxLen string, mysqlExtraParams map[string]string,
) *mysql.Config {
params := map[string]string{
"charset": "utf8",
Expand All @@ -44,3 +53,26 @@ func CreateMySQLConfig(user, password string, mysqlServiceHost string,
AllowNativePasswords: true,
}
}

func CreatePostgreSQLConfig(user, password, postgresHost, dbName string, postgresPort uint16,
) string {
var b bytes.Buffer
if dbName != "" {
fmt.Fprintf(&b, "database=%s ", dbName)
}
if user != "" {
fmt.Fprintf(&b, "user=%s ", user)
}
if password != "" {
fmt.Fprintf(&b, "password=%s ", password)
}
if postgresHost != "" {
fmt.Fprintf(&b, "host=%s ", postgresHost)
}
if postgresPort != 0 {
fmt.Fprintf(&b, "port=%d ", postgresPort)
}
fmt.Fprint(&b, "sslmode=disable")

return b.String()
}
Loading

0 comments on commit e1f0c01

Please sign in to comment.