Skip to content

Commit d91b9b9

Browse files
committed
DB: Rename var name & Remove new function
* Migration -> Initialization * Remove GetBoolEnvOrDefault
1 parent 69429b3 commit d91b9b9

File tree

5 files changed

+5
-36
lines changed

5 files changed

+5
-36
lines changed

pkg/db/v1beta1/common/const.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ const (
4747
DefaultPostgreSQLHost = "katib-postgres"
4848
DefaultPostgreSQLPort = "5432"
4949

50-
SkipDbMigrationEnvName = "SKIP_DB_MIGRATION"
50+
SkipDbInitializationEnvName = "SKIP_DB_INITIALIZATION"
5151
)

pkg/db/v1beta1/mysql/init.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import (
2525

2626
func (d *dbConn) DBInit() {
2727
db := d.db
28-
skipDbMigration := env.GetBoolEnvOrDefault(common.SkipDbMigrationEnvName, false)
28+
skipDbInitialization := env.GetEnvOrDefault(common.SkipDbInitializationEnvName, "false")
2929

30-
if !skipDbMigration {
30+
if skipDbInitialization == "false" {
3131
klog.Info("Initializing v1beta1 DB schema")
3232

3333
_, err := db.Exec(`CREATE TABLE IF NOT EXISTS observation_logs

pkg/db/v1beta1/postgres/init.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ import (
2626

2727
func (d *dbConn) DBInit() {
2828
db := d.db
29-
skipDbMigration := env.GetBoolEnvOrDefault(common.SkipDbMigrationEnvName, false)
29+
skipDbInitialization := env.GetEnvOrDefault(common.SkipDbInitializationEnvName, "false")
3030

31-
if !skipDbMigration {
31+
if skipDbInitialization == "false" {
3232
klog.Info("Initializing v1beta1 DB schema")
3333

3434
_, err := db.Exec(`CREATE TABLE IF NOT EXISTS observation_logs

pkg/util/v1beta1/env/env.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ limitations under the License.
1717
package env
1818

1919
import (
20-
"k8s.io/klog"
2120
"os"
22-
"strconv"
2321
)
2422

2523
func GetEnvOrDefault(key string, fallback string) string {
@@ -28,14 +26,3 @@ func GetEnvOrDefault(key string, fallback string) string {
2826
}
2927
return fallback
3028
}
31-
32-
func GetBoolEnvOrDefault(key string, fallback bool) bool {
33-
if value, ok := os.LookupEnv(key); ok {
34-
parsedValue, err := strconv.ParseBool(value)
35-
if err != nil {
36-
klog.Fatalf("Failed converting %s env to bool", key)
37-
}
38-
return parsedValue
39-
}
40-
return fallback
41-
}

pkg/util/v1beta1/env/env_test.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package env
1818

1919
import (
20-
"fmt"
2120
"os"
2221
"testing"
2322
)
@@ -36,20 +35,3 @@ func TestGetEnvWithDefault(t *testing.T) {
3635
t.Errorf("Expected %s, got %s", expected, v)
3736
}
3837
}
39-
40-
func TestGetBoolEnvWithDefault(t *testing.T) {
41-
expected := false
42-
key := "TEST"
43-
v := GetBoolEnvOrDefault(key, expected)
44-
if v != expected {
45-
t.Errorf("Expected %t, got %t", expected, v)
46-
}
47-
48-
expected = true
49-
envValue := fmt.Sprintf("%t", expected)
50-
os.Setenv(key, envValue)
51-
v = GetBoolEnvOrDefault(key, false)
52-
if v != expected {
53-
t.Errorf("Expected %t, got %t", expected, v)
54-
}
55-
}

0 commit comments

Comments
 (0)