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

Function main

coderd/database/gen/dump/main.go:51–126  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

49}
50
51func main() {
52 t := &mockTB{}
53
54 // Ensure cleanups run on both normal exit and SIGINT/SIGTERM.
55 // Go's default signal handlers call os.Exit, which skips deferred
56 // funcs and would leave an embedded-postgres daemon orphaned.
57 var cleanupOnce sync.Once
58 runCleanup := func() {
59 cleanupOnce.Do(func() {
60 for _, f := range t.cleanup {
61 f()
62 }
63 })
64 }
65 defer runCleanup()
66
67 sigCh := make(chan os.Signal, 1)
68 signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)
69 go func() {
70 <-sigCh
71 runCleanup()
72 os.Exit(130)
73 }()
74
75 connection := os.Getenv("DB_DUMP_CONNECTION_URL")
76 if connection == "" {
77 var cleanup func()
78 var err error
79 connection, cleanup, err = dbtestutil.OpenContainerized(t, dbtestutil.DBContainerOptions{})
80 if err != nil {
81 _, _ = fmt.Fprintf(os.Stderr, "containerized postgres unavailable (%s); falling back to embedded postgres\n", err)
82 connection, cleanup, err = openEmbeddedPostgres()
83 if err != nil {
84 panic(err)
85 }
86 }
87 t.Cleanup(cleanup)
88 }
89
90 db, err := sql.Open("postgres", connection)
91 if err != nil {
92 err = xerrors.Errorf("open database failed: %w", err)
93 panic(err)
94 }
95 defer db.Close()
96
97 err = migrations.Up(db)
98 if err != nil {
99 err = xerrors.Errorf("run migrations failed: %w", err)
100 panic(err)
101 }
102
103 dumpBytes, err := dbtestutil.PGDumpSchemaOnly(connection)
104 if err != nil {
105 if !pgDumpUsable() {
106 _, _ = fmt.Fprintf(os.Stderr,
107 "\nThis step needs pg_dump (PostgreSQL v13 or later) on PATH OR a Docker-compatible daemon.\n"+
108 "Install pg_dump locally to avoid Docker:\n"+

Callers

nothing calls this directly

Calls 13

CleanupMethod · 0.95
OpenContainerizedFunction · 0.92
UpFunction · 0.92
PGDumpSchemaOnlyFunction · 0.92
FileFunction · 0.92
openEmbeddedPostgresFunction · 0.85
pgDumpUsableFunction · 0.85
ExitMethod · 0.80
DoMethod · 0.65
CloseMethod · 0.65
NotifyMethod · 0.45
OpenMethod · 0.45

Tested by

no test coverage detected