Skip to content

Commit

Permalink
Actually use schema and db names specified in postgres db config
Browse files Browse the repository at this point in the history
  • Loading branch information
dhui committed Oct 14, 2019
1 parent bbe4ec3 commit 57b2ba7
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions database/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,34 @@ func WithInstance(instance *sql.DB, config *Config) (database.Driver, error) {
return nil, err
}

query := `SELECT CURRENT_DATABASE()`
var databaseName string
if err := instance.QueryRow(query).Scan(&databaseName); err != nil {
return nil, &database.Error{OrigErr: err, Query: []byte(query)}
}
if config.DatabaseName == "" {
query := `SELECT CURRENT_DATABASE()`
var databaseName string
if err := instance.QueryRow(query).Scan(&databaseName); err != nil {
return nil, &database.Error{OrigErr: err, Query: []byte(query)}
}

if len(databaseName) == 0 {
return nil, ErrNoDatabaseName
}

if len(databaseName) == 0 {
return nil, ErrNoDatabaseName
config.DatabaseName = databaseName
}

config.DatabaseName = databaseName
if config.SchemaName == "" {
query := `SELECT CURRENT_SCHEMA()`
var schemaName string
if err := instance.QueryRow(query).Scan(&schemaName); err != nil {
return nil, &database.Error{OrigErr: err, Query: []byte(query)}
}

query = `SELECT CURRENT_SCHEMA()`
var schemaName string
if err := instance.QueryRow(query).Scan(&schemaName); err != nil {
return nil, &database.Error{OrigErr: err, Query: []byte(query)}
}
if len(schemaName) == 0 {
return nil, ErrNoSchema
}

if len(schemaName) == 0 {
return nil, ErrNoSchema
config.SchemaName = schemaName
}

config.SchemaName = schemaName

if len(config.MigrationsTable) == 0 {
config.MigrationsTable = DefaultMigrationsTable
}
Expand Down

0 comments on commit 57b2ba7

Please sign in to comment.