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

Function setDBTimezone

coderd/database/dbtestutil/db.go:151–163  ·  view source on GitHub ↗

setRandDBTimezone sets the timezone of the database to the given timezone. Note that the updated timezone only comes into effect on reconnect, so we create our own connection for this and close the DB after we're done.

(t testing.TB, dbURL, dbname, tz string)

Source from the content-addressed store, hash-verified

149// Note that the updated timezone only comes into effect on reconnect, so we
150// create our own connection for this and close the DB after we're done.
151func setDBTimezone(t testing.TB, dbURL, dbname, tz string) {
152 t.Helper()
153
154 sqlDB, err := sql.Open("postgres", dbURL)
155 require.NoError(t, err)
156 defer func() {
157 _ = sqlDB.Close()
158 }()
159
160 // nolint: gosec // This unfortunately does not work with placeholders.
161 _, err = sqlDB.Exec(fmt.Sprintf("ALTER DATABASE %s SET TIMEZONE TO %q", dbname, tz))
162 require.NoError(t, err, "failed to set timezone for database")
163}
164
165// dbNameFromConnectionURL returns the database name from the given connection URL,
166// where connectionURL is of the form postgres://user:pass@host:port/dbname

Callers 1

NewDBFunction · 0.85

Calls 4

HelperMethod · 0.65
CloseMethod · 0.65
ExecMethod · 0.65
OpenMethod · 0.45

Tested by

no test coverage detected