···4343 id integer primary key autoincrement,
4444 last_time_us integer not null
4545 );
4646+4747+ create table if not exists oplog (
4848+ tid text primary key,
4949+ did text not null,
5050+ repo text not null,
5151+ old_sha text not null,
5252+ new_sha text not null,
5353+ ref text not null
5454+ );
4655 `)
4756 if err != nil {
4857 return nil, err
+63
knotserver/db/oplog.go
···11+package db
22+33+import (
44+ "fmt"
55+)
66+77+type Op struct {
88+ Tid string // time based ID, easy to enumerate & monotonic
99+ Did string // did of pusher
1010+ Repo string // <did/repo> fully qualified repo
1111+ OldSha string // old sha of reference being updated
1212+ NewSha string // new sha of reference being updated
1313+ Ref string // the reference being updated
1414+}
1515+1616+func (d *DB) InsertOp(op Op) error {
1717+ _, err := d.db.Exec(
1818+ `insert into oplog (tid, did, repo, old_sha, new_sha, ref) values (?, ?, ?, ?, ?, ?)`,
1919+ op.Tid,
2020+ op.Did,
2121+ op.Repo,
2222+ op.OldSha,
2323+ op.NewSha,
2424+ op.Ref,
2525+ )
2626+ return err
2727+}
2828+2929+func (d *DB) GetOps(cursor string) ([]Op, error) {
3030+ whereClause := ""
3131+ args := []any{}
3232+ if cursor != "" {
3333+ whereClause = "where tid > ?"
3434+ args = append(args, cursor)
3535+ }
3636+3737+ query := fmt.Sprintf(`
3838+ select tid, did, repo, old_sha, new_sha, ref
3939+ from oplog
4040+ %s
4141+ order by tid asc
4242+ limit 100
4343+ `, whereClause)
4444+4545+ rows, err := d.db.Query(query, args...)
4646+ if err != nil {
4747+ return nil, err
4848+ }
4949+ defer rows.Close()
5050+5151+ var ops []Op
5252+ for rows.Next() {
5353+ var op Op
5454+ rows.Scan(&op.Tid, &op.Did, &op.Repo, &op.OldSha, &op.NewSha, &op.Ref)
5555+ ops = append(ops, op)
5656+ }
5757+5858+ if err := rows.Err(); err != nil {
5959+ return nil, err
6060+ }
6161+6262+ return ops, nil
6363+}