Skip to content

Commit

Permalink
Merge pull request #93 from mattn/delete-fixup
Browse files Browse the repository at this point in the history
delete fixup
  • Loading branch information
mattn authored Oct 6, 2023
2 parents b7ce50a + 88aa2fd commit 470d025
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 470d025

Please sign in to comment.