-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdump.go
46 lines (39 loc) · 961 Bytes
/
dump.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"log"
"gorm.io/gorm"
)
func Dump() {
var holes Holes
var floors Floors
result := DB.Where("hidden = false").
FindInBatches(&holes, 1000, func(tx *gorm.DB, batch int) error {
if len(holes) == 0 {
return nil
}
holeIDs := make([]int, len(holes))
for i, hole := range holes {
holeIDs[i] = hole.ID
}
err := tx.
Table("floor").
Select("id", "content", "updated_at").
Where("hole_id in (?) and deleted = 0 and ((is_actual_sensitive IS NOT NULL AND is_actual_sensitive = false) OR (is_actual_sensitive IS NULL AND is_sensitive = false))", holeIDs).
Scan(&floors).Error
if err != nil {
return err
}
if len(floors) == 0 {
return nil
}
err = BulkInsert(floors)
if err != nil {
return err
}
log.Printf("insert holes [%d, %d]\n", holes[0].ID, holes[len(holes)-1].ID)
return nil
})
if result.Error != nil {
log.Fatalf("dump err: %s", result.Error)
}
}