Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 9238146

Browse files
sourcegraph-release-botStrum355unknwonDaedalusG
authored
[Backport 5.1] Migrator: db dsns behind SRC_LOG_LEVEL (#56836)
Co-authored-by: Noah S-C <[email protected]> Co-authored-by: Joe Chen <[email protected]> Co-authored-by: Warren Gifford <[email protected]>
1 parent e847ffa commit 9238146

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

internal/database/connections/live/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/database/connections/live/runner.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/sourcegraph/sourcegraph/internal/database/migration/runner"
1010
"github.com/sourcegraph/sourcegraph/internal/database/migration/schemas"
11+
"github.com/sourcegraph/sourcegraph/internal/env"
1112
"github.com/sourcegraph/sourcegraph/internal/observation"
1213
"github.com/sourcegraph/sourcegraph/lib/errors"
1314
"github.com/sourcegraph/sourcegraph/lib/output"
@@ -18,6 +19,7 @@ func RunnerFromDSNs(out *output.Output, logger log.Logger, dsns map[string]strin
1819
}
1920

2021
func RunnerFromDSNsWithSchemas(out *output.Output, logger log.Logger, dsns map[string]string, appName string, newStore StoreFactory, availableSchemas []*schemas.Schema) (*runner.Runner, error) {
22+
var verbose = env.LogLevel == "dbug"
2123
frontendSchema, ok := schemaByName(availableSchemas, "frontend")
2224
if !ok {
2325
return nil, errors.Newf("no available schema matches %q", "frontend")
@@ -33,13 +35,22 @@ func RunnerFromDSNsWithSchemas(out *output.Output, logger log.Logger, dsns map[s
3335
factory func(observationCtx *observation.Context, dsn, appName string) (*sql.DB, error),
3436
) runner.StoreFactory {
3537
return func(ctx context.Context) (runner.Store, error) {
36-
pending := out.Pending(output.Styledf(output.StylePending, "Attempting connection to %s", dsns[name]))
38+
var pending output.Pending
39+
if verbose {
40+
pending = out.Pending(output.Styledf(output.StylePending, "Attempting connection to %s: %s", schema.Name, dsns[name]))
41+
} else {
42+
pending = out.Pending(output.Styledf(output.StylePending, "Attempting connection to %s", schema.Name))
43+
}
3744
db, err := factory(observation.NewContext(logger), dsns[name], appName)
3845
if err != nil {
3946
pending.Destroy()
4047
return nil, err
4148
}
42-
pending.Complete(output.Emojif(output.EmojiSuccess, "Connection to %q succeeded", dsns[name]))
49+
if verbose {
50+
pending.Complete(output.Emojif(output.EmojiSuccess, "Connection to %s: %s succeeded", schema.Name, dsns[name]))
51+
} else {
52+
pending.Complete(output.Emojif(output.EmojiSuccess, "Connection to %s succeeded", schema.Name))
53+
}
4354

4455
return initStore(ctx, newStore, db, schema)
4556
}

internal/database/migration/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/database/migration/runner.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/sourcegraph/sourcegraph/internal/database/migration/schemas"
1010
"github.com/sourcegraph/sourcegraph/internal/database/migration/store"
1111
"github.com/sourcegraph/sourcegraph/internal/database/postgresdsn"
12+
"github.com/sourcegraph/sourcegraph/internal/env"
1213
"github.com/sourcegraph/sourcegraph/internal/observation"
1314
"github.com/sourcegraph/sourcegraph/lib/output"
1415
)
@@ -24,13 +25,15 @@ func NewRunnerWithSchemas(
2425
if err != nil {
2526
return nil, err
2627
}
28+
var verbose = env.LogLevel == "dbug"
2729

2830
var dsnsStrings []string
2931
for schema, dsn := range dsns {
3032
dsnsStrings = append(dsnsStrings, schema+" => "+dsn)
3133
}
32-
33-
out.WriteLine(output.Linef(output.EmojiInfo, output.StyleGrey, "Connection DSNs used: %s", strings.Join(dsnsStrings, ", ")))
34+
if verbose {
35+
out.WriteLine(output.Linef(output.EmojiInfo, output.StyleGrey, " Connection DSNs used: %s", strings.Join(dsnsStrings, ", ")))
36+
}
3437

3538
storeFactory := func(db *sql.DB, migrationsTable string) connections.Store {
3639
return connections.NewStoreShim(store.NewWithDB(observationCtx, db, migrationsTable))

0 commit comments

Comments
 (0)