appview/{db,models}: add avatar to profile #891

open
opened by anirudh.fi targeting master from icy/tolqpt
Changed files
+20 -4
appview
+9 -1
appview/db/db.go
··· 260 did text not null, 261 262 -- data 263 description text not null, 264 include_bluesky integer not null default 0, 265 location text, ··· 1078 // transfer data, constructing pull_at from pulls table 1079 _, err = tx.Exec(` 1080 insert into pull_submissions_new (id, pull_at, round_number, patch, created) 1081 - select 1082 ps.id, 1083 'at://' || p.owner_did || '/sh.tangled.repo.pull/' || p.rkey, 1084 ps.round_number, ··· 1173 return err 1174 }) 1175 1176 return &DB{ 1177 db, 1178 logger,
··· 260 did text not null, 261 262 -- data 263 + avatar text, 264 description text not null, 265 include_bluesky integer not null default 0, 266 location text, ··· 1079 // transfer data, constructing pull_at from pulls table 1080 _, err = tx.Exec(` 1081 insert into pull_submissions_new (id, pull_at, round_number, patch, created) 1082 + select 1083 ps.id, 1084 'at://' || p.owner_did || '/sh.tangled.repo.pull/' || p.rkey, 1085 ps.round_number, ··· 1174 return err 1175 }) 1176 1177 + orm.RunMigration(conn, logger, "add-avatar-to-profile", func(tx *sql.Tx) error { 1178 + _, err := tx.Exec(` 1179 + alter table profile add column avatar text; 1180 + `) 1181 + return err 1182 + }) 1183 + 1184 return &DB{ 1185 db, 1186 logger,
+10 -3
appview/db/profile.go
··· 128 _, err = tx.Exec( 129 `insert or replace into profile ( 130 did, 131 description, 132 include_bluesky, 133 location, 134 pronouns 135 ) 136 - values (?, ?, ?, ?, ?)`, 137 profile.Did, 138 profile.Description, 139 includeBskyValue, 140 profile.Location, ··· 312 func GetProfile(e Execer, did string) (*models.Profile, error) { 313 var profile models.Profile 314 var pronouns sql.Null[string] 315 316 profile.Did = did 317 318 includeBluesky := 0 319 320 err := e.QueryRow( 321 - `select description, include_bluesky, location, pronouns from profile where did = ?`, 322 did, 323 - ).Scan(&profile.Description, &includeBluesky, &profile.Location, &pronouns) 324 if err == sql.ErrNoRows { 325 profile := models.Profile{} 326 profile.Did = did ··· 339 profile.Pronouns = pronouns.V 340 } 341 342 rows, err := e.Query(`select link from profile_links where did = ?`, did) 343 if err != nil { 344 return nil, err
··· 128 _, err = tx.Exec( 129 `insert or replace into profile ( 130 did, 131 + avatar, 132 description, 133 include_bluesky, 134 location, 135 pronouns 136 ) 137 + values (?, ?, ?, ?, ?, ?)`, 138 profile.Did, 139 + profile.Avatar, 140 profile.Description, 141 includeBskyValue, 142 profile.Location, ··· 314 func GetProfile(e Execer, did string) (*models.Profile, error) { 315 var profile models.Profile 316 var pronouns sql.Null[string] 317 + var avatar sql.Null[string] 318 319 profile.Did = did 320 321 includeBluesky := 0 322 323 err := e.QueryRow( 324 + `select avatar, description, include_bluesky, location, pronouns from profile where did = ?`, 325 did, 326 + ).Scan(&avatar, &profile.Description, &includeBluesky, &profile.Location, &pronouns) 327 if err == sql.ErrNoRows { 328 profile := models.Profile{} 329 profile.Did = did ··· 342 profile.Pronouns = pronouns.V 343 } 344 345 + if avatar.Valid { 346 + profile.Avatar = avatar.V 347 + } 348 + 349 rows, err := e.Query(`select link from profile_links where did = ?`, did) 350 if err != nil { 351 return nil, err
+1
appview/models/profile.go
··· 13 Did string 14 15 // data 16 Description string 17 IncludeBluesky bool 18 Location string
··· 13 Did string 14 15 // data 16 + Avatar string // CID of the avatar blob 17 Description string 18 IncludeBluesky bool 19 Location string