MCPcopy Index your code
hub / github.com/coder/coder / connectDB

Function connectDB

scripts/develop/dbrecovery.go:529–541  ·  view source on GitHub ↗
(ctx context.Context, pgURL string)

Source from the content-addressed store, hash-verified

527}
528
529func connectDB(ctx context.Context, pgURL string) (*sql.DB, error) {
530 db, err := sql.Open("postgres", pgURL)
531 if err != nil {
532 return nil, xerrors.Errorf("open: %w", err)
533 }
534 pingCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
535 defer cancel()
536 if err := db.PingContext(pingCtx); err != nil {
537 _ = db.Close()
538 return nil, xerrors.Errorf("ping: %w", err)
539 }
540 return db, nil
541}
542
543func startTempPostgresSetURL(ctx context.Context, logger slog.Logger, cfg *devConfig, pgURL *string) (func(), error) {
544 pgDir := filepath.Join(cfg.configDir, "postgres")

Callers 2

recoverDBFunction · 0.85
updateMigrationTrackingFunction · 0.85

Calls 3

CloseMethod · 0.65
OpenMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected