MCPcopy Index your code
hub / github.com/bytebase/bytebase / StartAllSampleInstances

Function StartAllSampleInstances

backend/resources/postgres/sample_instance.go:38–75  ·  view source on GitHub ↗

StartAllSampleInstances starts all postgres sample instances.

(ctx context.Context, dataDir string, basePort int)

Source from the content-addressed store, hash-verified

36
37// StartAllSampleInstances starts all postgres sample instances.
38func StartAllSampleInstances(ctx context.Context, dataDir string, basePort int) []func() {
39 sampleData, err := loadSampleData()
40 if err != nil {
41 slog.Error("failed to load sample data", log.BBError(err))
42 return nil
43 }
44
45 slog.Info("-----Sample Postgres Instance BEGIN-----")
46 stoppers := []func(){}
47 for i, env := range envs {
48 port := basePort + i
49 dataDir := path.Join(dataDir, "pgdata-sample", env)
50
51 if err := initDB(dataDir, SampleUser); err != nil {
52 slog.Error("failed to init sample instance", log.BBError(err))
53 continue
54 }
55
56 slog.Info(fmt.Sprintf("Start sample instance %v at port %d", env, port))
57 if err := start(port, dataDir, true /* serverLog */); err != nil {
58 slog.Error("failed to start sample instance", log.BBError(err))
59 continue
60 }
61 stoppers = append(stoppers, func() {
62 if err := stop(dataDir); err != nil {
63 panic(err)
64 }
65 })
66
67 if err := setupSampleInstance(ctx, envDB[env], port, sampleData); err != nil {
68 slog.Error("failed to init sample instance", log.BBError(err))
69 continue
70 }
71 }
72
73 slog.Info("-----Sample Postgres Instance END-----")
74 return stoppers
75}
76
77func loadSampleData() (string, error) {
78 // Load sample data

Callers 2

StartIfExistMethod · 0.92

Calls 9

BBErrorFunction · 0.92
loadSampleDataFunction · 0.85
initDBFunction · 0.85
stopFunction · 0.85
setupSampleInstanceFunction · 0.85
InfoMethod · 0.80
JoinMethod · 0.80
startFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected