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 37537e27..49b1cc75 100644 --- a/appview/db/profile.go +++ b/appview/db/profile.go @@ -158,13 +158,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, @@ -347,15 +349,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 @@ -374,6 +377,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