From 316b720a03de8517787c85de6be5abe4d444a179 Mon Sep 17 00:00:00 2001 From: Anirudh Oppiliappan Date: Fri, 12 Dec 2025 11:28:28 +0200 Subject: [PATCH] appview/{db,models}: add avatar to profile Change-Id: rurvxorukpxxywrrkvrrxwwouszqurqt Signed-off-by: Anirudh Oppiliappan --- appview/db/db.go | 10 +++++++++- appview/db/profile.go | 13 ++++++++++--- appview/models/profile.go | 1 + 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/appview/db/db.go b/appview/db/db.go index f4d5d93a..e6ef3143 100644 --- a/appview/db/db.go +++ b/appview/db/db.go @@ -260,6 +260,7 @@ func Make(ctx context.Context, dbPath string) (*DB, error) { did text not null, -- data + avatar text, description text not null, include_bluesky integer not null default 0, location text, @@ -1078,7 +1079,7 @@ func Make(ctx context.Context, dbPath string) (*DB, error) { // transfer data, constructing pull_at from pulls table _, err = tx.Exec(` insert into pull_submissions_new (id, pull_at, round_number, patch, created) - select + select ps.id, 'at://' || p.owner_did || '/sh.tangled.repo.pull/' || p.rkey, ps.round_number, @@ -1173,6 +1174,13 @@ func Make(ctx context.Context, dbPath string) (*DB, error) { return err }) + orm.RunMigration(conn, logger, "add-avatar-to-profile", func(tx *sql.Tx) error { + _, err := tx.Exec(` + alter table profile add column avatar text; + `) + return err + }) + return &DB{ db, logger, diff --git a/appview/db/profile.go b/appview/db/profile.go index a366a9e1..206e5c43 100644 --- a/appview/db/profile.go +++ b/appview/db/profile.go @@ -128,13 +128,15 @@ func UpsertProfile(tx *sql.Tx, profile *models.Profile) error { _, err = tx.Exec( `insert or replace into profile ( did, + avatar, description, include_bluesky, location, pronouns ) - values (?, ?, ?, ?, ?)`, + values (?, ?, ?, ?, ?, ?)`, profile.Did, + profile.Avatar, profile.Description, includeBskyValue, profile.Location, @@ -312,15 +314,16 @@ func GetProfiles(e Execer, filters ...orm.Filter) (map[string]*models.Profile, e func GetProfile(e Execer, did string) (*models.Profile, error) { var profile models.Profile var pronouns sql.Null[string] + var avatar sql.Null[string] profile.Did = did includeBluesky := 0 err := e.QueryRow( - `select description, include_bluesky, location, pronouns from profile where did = ?`, + `select avatar, description, include_bluesky, location, pronouns from profile where did = ?`, did, - ).Scan(&profile.Description, &includeBluesky, &profile.Location, &pronouns) + ).Scan(&avatar, &profile.Description, &includeBluesky, &profile.Location, &pronouns) if err == sql.ErrNoRows { profile := models.Profile{} profile.Did = did @@ -339,6 +342,10 @@ func GetProfile(e Execer, did string) (*models.Profile, error) { profile.Pronouns = pronouns.V } + if avatar.Valid { + profile.Avatar = avatar.V + } + rows, err := e.Query(`select link from profile_links where did = ?`, did) if err != nil { return nil, err diff --git a/appview/models/profile.go b/appview/models/profile.go index 193ce448..291d8b2e 100644 --- a/appview/models/profile.go +++ b/appview/models/profile.go @@ -13,6 +13,7 @@ type Profile struct { Did string // data + Avatar string // CID of the avatar blob Description string IncludeBluesky bool Location string -- 2.43.0