forked from tangled.org/core
this repo has no description

appview/db: make registration.secrets nullable and Add/DeleteKnot helpers

Signed-off-by: Anirudh Oppiliappan <anirudh@tangled.sh>

Changed files
+55
appview
+25
appview/db/db.go
···
return nil
})
+
// drop all knot secrets, add unique constraint to knots
+
//
+
// knots will henceforth use service auth for signed requests
+
runMigration(conn, "no-more-secrets", func(tx *sql.Tx) error {
+
_, err := tx.Exec(`
+
create table registrations_new (
+
id integer primary key autoincrement,
+
domain text not null,
+
did text not null,
+
created text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
+
registered text,
+
read_only integer not null default 0,
+
unique(domain, did)
+
);
+
+
insert into registrations_new (id, domain, did, created, registered, read_only)
+
select id, domain, did, created, registered, 1 from registrations
+
where registered is not null;
+
+
drop table registrations;
+
alter table registrations_new rename to registrations;
+
`)
+
return err
+
})
+
// recreate and add rkey + created columns with default constraint
runMigration(conn, "rework-collaborators-table", func(tx *sql.Tx) error {
// create new table
+30
appview/db/registration.go
···
"encoding/hex"
"fmt"
"log"
+
"strings"
"time"
)
+
// Registration represents a knot registration. Knot would've been a better
+
// name but we're stuck with this for historical reasons.
type Registration struct {
Id int64
Domain string
···
return err
}
+
+
func AddKnot(e Execer, domain, did string) error {
+
_, err := e.Exec(`
+
insert into registrations (domain, did)
+
values (?, ?)
+
`, domain, did)
+
return err
+
}
+
+
func DeleteKnot(e Execer, filters ...filter) error {
+
var conditions []string
+
var args []any
+
for _, filter := range filters {
+
conditions = append(conditions, filter.Condition())
+
args = append(args, filter.Arg()...)
+
}
+
+
whereClause := ""
+
if conditions != nil {
+
whereClause = " where " + strings.Join(conditions, " and ")
+
}
+
+
query := fmt.Sprintf(`delete from registrations %s`, whereClause)
+
+
_, err := e.Exec(query, args...)
+
return err
+
}