copy zones and records for testing

This commit is contained in:
pascal
2026-04-24 15:50:49 +02:00
parent 312bcf6398
commit 9b10d74ab8

View File

@@ -2917,6 +2917,10 @@ func NewPostgresqlStoreFromSqlStore(ctx context.Context, sqliteStore *SqlStore,
}
}
if err = copyZonesAndRecords(sqliteStore, store); err != nil {
return nil, err
}
return store, nil
}
@@ -2983,9 +2987,28 @@ func NewMysqlStoreFromSqlStore(ctx context.Context, sqliteStore *SqlStore, dsn s
}
}
if err = copyZonesAndRecords(sqliteStore, store); err != nil {
return nil, err
}
return store, nil
}
func copyZonesAndRecords(src, dst *SqlStore) error {
var srcZones []*zones.Zone
if err := src.db.Preload("Records").Find(&srcZones).Error; err != nil {
return fmt.Errorf("failed to read zones from source store: %w", err)
}
for _, zone := range srcZones {
if err := dst.db.Create(zone).Error; err != nil {
return fmt.Errorf("failed to copy zone %s: %w", zone.ID, err)
}
}
return nil
}
func (s *SqlStore) GetSetupKeyBySecret(ctx context.Context, lockStrength LockingStrength, key string) (*types.SetupKey, error) {
tx := s.db
if lockStrength != LockingStrengthNone {