From abd0068031f1cdac952cc8b5fcea9a68a78c0f2f Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Fri, 30 Jan 2026 05:52:21 +0000 Subject: [PATCH] appview/db: remove profile vanity stats constraints this allows ingesting newer types of stats. Signed-off-by: oppiliappan --- appview/db/db.go | 24 +++++++++++++++++++ appview/db/profile.go | 4 +++- appview/models/profile.go | 2 +- .../templates/user/fragments/editBio.html | 1 + 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/appview/db/db.go b/appview/db/db.go index e6ef3143..0ab90fc8 100644 --- a/appview/db/db.go +++ b/appview/db/db.go @@ -1181,6 +1181,30 @@ func Make(ctx context.Context, dbPath string) (*DB, error) { return err }) + orm.RunMigration(conn, logger, "remove-profile-stats-column-constraint", func(tx *sql.Tx) error { + _, err := tx.Exec(` + -- create new table without the check constraint + create table profile_stats_new ( + id integer primary key autoincrement, + did text not null, + kind text not null, -- no constraint this time + foreign key (did) references profile(did) on delete cascade + ); + + -- copy data from old table + insert into profile_stats_new (id, did, kind) + select id, did, kind + from profile_stats; + + -- drop old table + drop table profile_stats; + + -- rename new table + alter table profile_stats_new rename to profile_stats; + `) + return err + }) + return &DB{ db, logger, diff --git a/appview/db/profile.go b/appview/db/profile.go index 9853c51b..0d490d17 100644 --- a/appview/db/profile.go +++ b/appview/db/profile.go @@ -451,8 +451,10 @@ func GetVanityStat(e Execer, did string, stat models.VanityStatKind) (uint64, er query = `select count(id) from repos where did = ?` args = append(args, did) case models.VanityStatStarCount: - query = `select count(id) from stars where did = ?` + query = `select count(id) from stars where subject_at like 'at://' || ? || '%'` args = append(args, did) + default: + return 0, fmt.Errorf("invalid vanity stat kind: %s", stat) } var result uint64 diff --git a/appview/models/profile.go b/appview/models/profile.go index 86285ae9..f3724a25 100644 --- a/appview/models/profile.go +++ b/appview/models/profile.go @@ -77,7 +77,7 @@ func (v VanityStatKind) String() string { case VanityStatRepositoryCount: return "Repositories" case VanityStatStarCount: - return "Stars" + return "Stars Received" } return "" } diff --git a/appview/pages/templates/user/fragments/editBio.html b/appview/pages/templates/user/fragments/editBio.html index 8a7f0cd9..704bc682 100644 --- a/appview/pages/templates/user/fragments/editBio.html +++ b/appview/pages/templates/user/fragments/editBio.html @@ -118,6 +118,7 @@ "open-issue-count" "Open Issue Count" "closed-issue-count" "Closed Issue Count" "repository-count" "Repository Count" + "star-count" "Star Count" }} {{ range $s := $stats }} {{ $value := index $s 0 }} -- 2.51.2