From cc0dc9e983f6a4e547b32faa095a33dfd86e3aa5 Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Wed, 10 Dec 2025 04:04:45 +0000 Subject: [PATCH] knotserver: add ability to run migrations on knots Change-Id: kkrssutvzqvxpwqkqzxmlsprtpotlwmo Signed-off-by: oppiliappan --- knotserver/db/db.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/knotserver/db/db.go b/knotserver/db/db.go index 9783848b..dbfd58a3 100644 --- a/knotserver/db/db.go +++ b/knotserver/db/db.go @@ -32,11 +32,13 @@ func Setup(ctx context.Context, dbPath string) (*DB, error) { return nil, err } - // NOTE: If any other migration is added here, you MUST - // copy the pattern in appview: use a single sql.Conn - // for every migration. + conn, err := db.Conn(ctx) + if err != nil { + return nil, err + } + defer conn.Close() - _, err = db.Exec(` + _, err = conn.ExecContext(ctx, ` create table if not exists known_dids ( did text primary key ); @@ -62,6 +64,11 @@ func Setup(ctx context.Context, dbPath string) (*DB, error) { created integer not null default (strftime('%s', 'now')), primary key (rkey, nsid) ); + + create table if not exists migrations ( + id integer primary key autoincrement, + name text unique + ); `) if err != nil { return nil, err -- 2.43.0