MCPcopy
hub / github.com/apache/devlake / prepareDB

Method prepareDB

backend/test/helper/client.go:295–327  ·  view source on GitHub ↗
(cfg *LocalClientConfig)

Source from the content-addressed store, hash-verified

293}
294
295func (d *DevlakeClient) prepareDB(cfg *LocalClientConfig) {
296 d.testCtx.Helper()
297 migrator := d.db.Migrator()
298 tables, err := migrator.GetTables()
299 require.NoError(d.testCtx, err)
300 d.log.Debug("Existing DB tables: %v", tables)
301 if cfg.DropDb {
302 d.log.Info("Dropping %d tables", len(tables))
303 var tablesRaw []any
304 for _, table := range tables {
305 tablesRaw = append(tablesRaw, table)
306 }
307 err = migrator.DropTable(tablesRaw...)
308 require.NoError(d.testCtx, err)
309 } else if cfg.TruncateDb {
310 if len(tables) > len(dbTruncationExclusions) {
311 d.log.Info("Truncating %d tables", len(tables)-len(dbTruncationExclusions))
312 }
313 for _, table := range tables {
314 excluded := false
315 for _, exclusion := range dbTruncationExclusions {
316 if exclusion == table {
317 excluded = true
318 break
319 }
320 }
321 if !excluded {
322 err = d.db.Exec("DELETE FROM " + table).Error
323 require.NoError(d.testCtx, err)
324 }
325 }
326 }
327}
328
329func runWithTimeout(timeout time.Duration, f func() (bool, errors.Error)) errors.Error {
330 if timeout == 0 {

Callers 2

ConnectRemoteServerFunction · 0.95
ConnectLocalServerFunction · 0.95

Calls 3

DebugMethod · 0.65
InfoMethod · 0.65
ExecMethod · 0.65

Tested by

no test coverage detected