Skip to content

Commit

Permalink
delete fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
mattn committed Oct 6, 2023
1 parent b7ce50a commit 88aa2fd
Showing 1 changed file with 0 additions and 22 deletions.
22 changes: 0 additions & 22 deletions storage/sqlite3/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,11 @@ var ddls = []string{
`CREATE INDEX IF NOT EXISTS kindidx ON event(kind)`,
}

func fixup(db *sqlx.DB) {
row, err := db.Query(`SELECT id, rowid FROM event GROUP BY id HAVING COUNT(id) > 1`)
if err == nil {
for row.Next() {
var id, rowid string
err = row.Scan(&id, &rowid)
if err != nil {
continue
}
result, err := db.Exec(`DELETE FROM event WHERE id = ? AND rowid != ?`, id, rowid)
if err != nil {
continue
}
num, _ := result.RowsAffected()
println(id, rowid, num)
}
row.Close()
println("DONE")
}
}

func (b *SQLite3Backend) Init() error {
db, err := sqlx.Connect("sqlite3", b.DatabaseURL)
if err != nil {
return err
}
fixup(db)

db.SetMaxOpenConns(b.MaxOpenConns)
db.SetMaxIdleConns(b.MaxIdleConns)
Expand Down

0 comments on commit 88aa2fd

Please sign in to comment.