Skip to content

Commit

Permalink
define schema name with env
Browse files Browse the repository at this point in the history
  • Loading branch information
Øyvind Hatland committed Nov 16, 2023
1 parent 3ee1ef5 commit cb48b33
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ func Connect() {
logrus.Error("DB_NAME environment variable not set")
}

schemaName, exists := os.LookupEnv("DB_SCHEMA_NAME")
if !exists {
logrus.Error("DB_NAME environment variable not set, using default name: navnetjener")
schemaName = "navnetjener"
}

port, exists := os.LookupEnv("DB_PORT")
if !exists {
logrus.Error("DB_PORT environment variable not set")
Expand All @@ -49,7 +55,7 @@ func Connect() {
dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=%s TimeZone=Europe/Oslo", host, username, password, databaseName, port, sslmode)
gormConfig := &gorm.Config{
NamingStrategy: schema.NamingStrategy{
TablePrefix: "navnetjener.",
TablePrefix: schemaName + ".",
SingularTable: false,
}}

Expand Down

0 comments on commit cb48b33

Please sign in to comment.