(cfg *LocalClientConfig)
| 293 | } |
| 294 | |
| 295 | func (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 | |
| 329 | func runWithTimeout(timeout time.Duration, f func() (bool, errors.Error)) errors.Error { |
| 330 | if timeout == 0 { |
no test coverage detected