···600600 return nil
601601 })
602602603603+ // make registrations.secret nullable for unified registration flow
604604+ runMigration(db, "make-registrations-secret-nullable", func(tx *sql.Tx) error {
605605+ // sqlite doesn't support ALTER COLUMN, so we need to recreate the table
606606+ _, err := tx.Exec(`
607607+ create table registrations_new (
608608+ id integer primary key autoincrement,
609609+ domain text not null unique,
610610+ did text not null,
611611+ secret text,
612612+ created text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
613613+ registered text
614614+ );
615615+616616+ insert into registrations_new (id, domain, did, secret, created, registered)
617617+ select id, domain, did, secret, created, registered from registrations;
618618+619619+ drop table registrations;
620620+ alter table registrations_new rename to registrations;
621621+ `)
622622+ return err
623623+ })
624624+603625 // recreate and add rkey + created columns with default constraint
604626 runMigration(db, "rework-collaborators-table", func(tx *sql.Tx) error {
605627 // create new table
+30
appview/db/registration.go
···66 "encoding/hex"
77 "fmt"
88 "log"
99+ "strings"
910 "time"
1011)
11121313+// Registration represents a knot registration. Knot would've been a better
1414+// name but we're stuck with this for historical reasons.
1215type Registration struct {
1316 Id int64
1417 Domain string
···187190188191 return err
189192}
193193+194194+func AddKnot(e Execer, domain, did string) error {
195195+ _, err := e.Exec(`
196196+ insert into registrations (domain, did)
197197+ values (?, ?)
198198+ `, domain, did)
199199+ return err
200200+}
201201+202202+func DeleteKnot(e Execer, filters ...filter) error {
203203+ var conditions []string
204204+ var args []any
205205+ for _, filter := range filters {
206206+ conditions = append(conditions, filter.Condition())
207207+ args = append(args, filter.Arg()...)
208208+ }
209209+210210+ whereClause := ""
211211+ if conditions != nil {
212212+ whereClause = " where " + strings.Join(conditions, " and ")
213213+ }
214214+215215+ query := fmt.Sprintf(`delete from registrations %s`, whereClause)
216216+217217+ _, err := e.Exec(query, args...)
218218+ return err
219219+}