+25
appview/db/db.go
+25
appview/db/db.go
···
612
612
return nil
613
613
})
614
614
615
+
// drop all knot secrets, add unique constraint to knots
616
+
//
617
+
// knots will henceforth use service auth for signed requests
618
+
runMigration(conn, "no-more-secrets", func(tx *sql.Tx) error {
619
+
_, err := tx.Exec(`
620
+
create table registrations_new (
621
+
id integer primary key autoincrement,
622
+
domain text not null,
623
+
did text not null,
624
+
created text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
625
+
registered text,
626
+
read_only integer not null default 0,
627
+
unique(domain, did)
628
+
);
629
+
630
+
insert into registrations_new (id, domain, did, created, registered, read_only)
631
+
select id, domain, did, created, registered, 1 from registrations
632
+
where registered is not null;
633
+
634
+
drop table registrations;
635
+
alter table registrations_new rename to registrations;
636
+
`)
637
+
return err
638
+
})
639
+
615
640
// recreate and add rkey + created columns with default constraint
616
641
runMigration(conn, "rework-collaborators-table", func(tx *sql.Tx) error {
617
642
// create new table
+30
appview/db/registration.go
+30
appview/db/registration.go
···
6
6
"encoding/hex"
7
7
"fmt"
8
8
"log"
9
+
"strings"
9
10
"time"
10
11
)
11
12
13
+
// Registration represents a knot registration. Knot would've been a better
14
+
// name but we're stuck with this for historical reasons.
12
15
type Registration struct {
13
16
Id int64
14
17
Domain string
···
187
190
188
191
return err
189
192
}
193
+
194
+
func AddKnot(e Execer, domain, did string) error {
195
+
_, err := e.Exec(`
196
+
insert into registrations (domain, did)
197
+
values (?, ?)
198
+
`, domain, did)
199
+
return err
200
+
}
201
+
202
+
func DeleteKnot(e Execer, filters ...filter) error {
203
+
var conditions []string
204
+
var args []any
205
+
for _, filter := range filters {
206
+
conditions = append(conditions, filter.Condition())
207
+
args = append(args, filter.Arg()...)
208
+
}
209
+
210
+
whereClause := ""
211
+
if conditions != nil {
212
+
whereClause = " where " + strings.Join(conditions, " and ")
213
+
}
214
+
215
+
query := fmt.Sprintf(`delete from registrations %s`, whereClause)
216
+
217
+
_, err := e.Exec(query, args...)
218
+
return err
219
+
}