Monorepo for Tangled tangled.org

appview: add repo_did columns, migrations, and model struct fields #1138

open opened by oyster.cafe targeting master from oyster.cafe/tangled-core: master
Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:3fwecdnvtcscjnrx2p4n7alz/sh.tangled.repo.pull/3mgprvt2ejx22
+106 -347
Interdiff #8 #9
-279
appview/db/db.go
··· 1291 1291 _, err := tx.Exec(` 1292 1292 alter table repos add column repo_did text; 1293 1293 create unique index if not exists idx_repos_repo_did on repos(repo_did); 1294 - 1295 - alter table issues add column repo_did text; 1296 - alter table pulls add column repo_did text; 1297 - alter table artifacts add column repo_did text; 1298 - alter table webhooks add column repo_did text; 1299 - alter table collaborators add column repo_did text; 1300 - alter table pull_comments add column repo_did text; 1301 - alter table profile_pinned_repositories add column repo_did text; 1302 - alter table repo_issue_seqs add column repo_did text; 1303 - alter table repo_pull_seqs add column repo_did text; 1304 - alter table repo_languages add column repo_did text; 1305 - alter table repo_labels add column repo_did text; 1306 - alter table stars add column subject_did text; 1307 - `) 1308 - return err 1309 - }) 1310 - 1311 - conn.ExecContext(ctx, "pragma foreign_keys = off;") 1312 - orm.RunMigration(conn, logger, "add-repo-did-fk-constraints", func(tx *sql.Tx) error { 1313 - _, err := tx.Exec(` 1314 - create table repo_issue_seqs_new ( 1315 - repo_at text primary key, 1316 - next_issue_id integer not null default 1, 1317 - repo_did text, 1318 - foreign key (repo_did) references repos(repo_did) on delete cascade 1319 - ); 1320 - insert into repo_issue_seqs_new select repo_at, next_issue_id, repo_did from repo_issue_seqs; 1321 - drop table repo_issue_seqs; 1322 - alter table repo_issue_seqs_new rename to repo_issue_seqs; 1323 - 1324 - create table repo_pull_seqs_new ( 1325 - repo_at text primary key, 1326 - next_pull_id integer not null default 1, 1327 - repo_did text, 1328 - foreign key (repo_did) references repos(repo_did) on delete cascade 1329 - ); 1330 - insert into repo_pull_seqs_new select repo_at, next_pull_id, repo_did from repo_pull_seqs; 1331 - drop table repo_pull_seqs; 1332 - alter table repo_pull_seqs_new rename to repo_pull_seqs; 1333 - 1334 - create table repo_languages_new ( 1335 - id integer primary key autoincrement, 1336 - repo_at text not null, 1337 - ref text not null, 1338 - is_default_ref integer not null default 0, 1339 - language text not null, 1340 - bytes integer not null check (bytes >= 0), 1341 - repo_did text, 1342 - unique(repo_at, ref, language), 1343 - foreign key (repo_did) references repos(repo_did) on delete cascade 1344 - ); 1345 - insert into repo_languages_new select id, repo_at, ref, is_default_ref, language, bytes, repo_did from repo_languages; 1346 - drop table repo_languages; 1347 - alter table repo_languages_new rename to repo_languages; 1348 - 1349 - create table repo_labels_new ( 1350 - id integer primary key autoincrement, 1351 - repo_at text not null, 1352 - label_at text not null, 1353 - repo_did text, 1354 - unique (repo_at, label_at), 1355 - foreign key (repo_did) references repos(repo_did) on delete cascade 1356 - ); 1357 - insert into repo_labels_new select id, repo_at, label_at, repo_did from repo_labels; 1358 - drop table repo_labels; 1359 - alter table repo_labels_new rename to repo_labels; 1360 - `) 1361 - return err 1362 - }) 1363 - conn.ExecContext(ctx, "pragma foreign_keys = on;") 1364 - 1365 - orm.RunMigration(conn, logger, "add-repo-did-indexes", func(tx *sql.Tx) error { 1366 - _, err := tx.Exec(` 1367 - create index if not exists idx_issues_repo_did on issues(repo_did); 1368 - create index if not exists idx_pulls_repo_did on pulls(repo_did); 1369 - create index if not exists idx_artifacts_repo_did on artifacts(repo_did); 1370 - create index if not exists idx_collaborators_repo_did on collaborators(repo_did); 1371 - create index if not exists idx_pull_comments_repo_did on pull_comments(repo_did); 1372 - create index if not exists idx_stars_subject_did on stars(subject_did); 1373 - `) 1374 - return err 1375 - }) 1376 - 1377 - orm.RunMigration(conn, logger, "add-repo-did-indexes-2", func(tx *sql.Tx) error { 1378 - _, err := tx.Exec(` 1379 - create index if not exists idx_repo_issue_seqs_repo_did on repo_issue_seqs(repo_did); 1380 - create index if not exists idx_repo_pull_seqs_repo_did on repo_pull_seqs(repo_did); 1381 - create index if not exists idx_repo_languages_repo_did on repo_languages(repo_did); 1382 - create index if not exists idx_repo_labels_repo_did on repo_labels(repo_did); 1383 - create index if not exists idx_webhooks_repo_did on webhooks(repo_did); 1384 1294 `) 1385 1295 return err 1386 1296 }) ··· 1411 1321 return err 1412 1322 }) 1413 1323 1414 - conn.ExecContext(ctx, "pragma foreign_keys = off;") 1415 - orm.RunMigration(conn, logger, "add-repo-did-fk-content-tables", func(tx *sql.Tx) error { 1416 - _, err := tx.Exec(` 1417 - -- issues: add FK on repo_did 1418 - create table issues_fk ( 1419 - id integer primary key autoincrement, 1420 - did text not null, 1421 - rkey text not null, 1422 - at_uri text generated always as ('at://' || did || '/' || 'sh.tangled.repo.issue' || '/' || rkey) stored, 1423 - repo_at text not null, 1424 - issue_id integer not null, 1425 - title text not null, 1426 - body text not null, 1427 - open integer not null default 1, 1428 - created text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')), 1429 - edited text, 1430 - deleted text, 1431 - repo_did text, 1432 - unique(did, rkey), 1433 - unique(repo_at, issue_id), 1434 - unique(at_uri), 1435 - foreign key (repo_at) references repos(at_uri) on delete cascade, 1436 - foreign key (repo_did) references repos(repo_did) on delete set null 1437 - ); 1438 - insert into issues_fk (id, did, rkey, repo_at, issue_id, title, body, open, created, edited, deleted, repo_did) 1439 - select id, did, rkey, repo_at, issue_id, title, body, open, created, edited, deleted, repo_did from issues; 1440 - drop table issues; 1441 - alter table issues_fk rename to issues; 1442 - create index if not exists idx_issues_repo_did on issues(repo_did); 1443 - 1444 - -- pulls: add FK on repo_did 1445 - create table pulls_fk ( 1446 - id integer primary key autoincrement, 1447 - pull_id integer not null, 1448 - at_uri text generated always as ('at://' || owner_did || '/' || 'sh.tangled.repo.pull' || '/' || rkey) stored, 1449 - repo_at text not null, 1450 - owner_did text not null, 1451 - rkey text not null, 1452 - title text not null, 1453 - body text not null, 1454 - target_branch text not null, 1455 - state integer not null default 0 check (state in (0, 1, 2, 3)), 1456 - source_branch text, 1457 - source_repo_at text, 1458 - stack_id text, 1459 - change_id text, 1460 - parent_change_id text, 1461 - created text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')), 1462 - repo_did text, 1463 - unique(repo_at, pull_id), 1464 - unique(at_uri), 1465 - foreign key (repo_at) references repos(at_uri) on delete cascade, 1466 - foreign key (repo_did) references repos(repo_did) on delete set null 1467 - ); 1468 - insert into pulls_fk (id, pull_id, repo_at, owner_did, rkey, title, body, target_branch, state, source_branch, source_repo_at, stack_id, change_id, parent_change_id, created, repo_did) 1469 - select id, pull_id, repo_at, owner_did, rkey, title, body, target_branch, state, source_branch, source_repo_at, stack_id, change_id, parent_change_id, created, repo_did from pulls; 1470 - drop table pulls; 1471 - alter table pulls_fk rename to pulls; 1472 - create index if not exists idx_pulls_repo_did on pulls(repo_did); 1473 - 1474 - -- artifacts: add FK on repo_did 1475 - create table artifacts_fk ( 1476 - id integer primary key autoincrement, 1477 - did text not null, 1478 - rkey text not null, 1479 - repo_at text not null, 1480 - tag binary(20) not null, 1481 - created text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')), 1482 - blob_cid text not null, 1483 - name text not null, 1484 - size integer not null default 0, 1485 - mimetype string not null default '*/*', 1486 - repo_did text, 1487 - unique(did, rkey), 1488 - unique(repo_at, tag, name), 1489 - foreign key (repo_at) references repos(at_uri) on delete cascade, 1490 - foreign key (repo_did) references repos(repo_did) on delete set null 1491 - ); 1492 - insert into artifacts_fk (id, did, rkey, repo_at, tag, created, blob_cid, name, size, mimetype, repo_did) 1493 - select id, did, rkey, repo_at, tag, created, blob_cid, name, size, mimetype, repo_did from artifacts; 1494 - drop table artifacts; 1495 - alter table artifacts_fk rename to artifacts; 1496 - create index if not exists idx_artifacts_repo_did on artifacts(repo_did); 1497 - 1498 - -- webhooks: add FK on repo_did 1499 - create table webhooks_fk ( 1500 - id integer primary key autoincrement, 1501 - repo_at text not null, 1502 - url text not null, 1503 - secret text, 1504 - active integer not null default 1, 1505 - events text not null, 1506 - created_at text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')), 1507 - updated_at text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')), 1508 - repo_did text, 1509 - foreign key (repo_at) references repos(at_uri) on delete cascade, 1510 - foreign key (repo_did) references repos(repo_did) on delete set null 1511 - ); 1512 - insert into webhooks_fk (id, repo_at, url, secret, active, events, created_at, updated_at, repo_did) 1513 - select id, repo_at, url, secret, active, events, created_at, updated_at, repo_did from webhooks; 1514 - drop table webhooks; 1515 - alter table webhooks_fk rename to webhooks; 1516 - create index if not exists idx_webhooks_repo_did on webhooks(repo_did); 1517 - 1518 - -- collaborators: add FK on repo_did 1519 - create table collaborators_fk ( 1520 - id integer primary key autoincrement, 1521 - did text not null, 1522 - rkey text, 1523 - subject_did text not null, 1524 - repo_at text not null, 1525 - created text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')), 1526 - repo_did text, 1527 - foreign key (repo_at) references repos(at_uri) on delete cascade, 1528 - foreign key (repo_did) references repos(repo_did) on delete set null 1529 - ); 1530 - insert into collaborators_fk (id, did, rkey, subject_did, repo_at, created, repo_did) 1531 - select id, did, rkey, subject_did, repo_at, created, repo_did from collaborators; 1532 - drop table collaborators; 1533 - alter table collaborators_fk rename to collaborators; 1534 - create index if not exists idx_collaborators_repo_did on collaborators(repo_did); 1535 - 1536 - -- pull_comments: add FK on repo_did 1537 - create table pull_comments_fk ( 1538 - id integer primary key autoincrement, 1539 - pull_id integer not null, 1540 - submission_id integer not null, 1541 - repo_at text not null, 1542 - owner_did text not null, 1543 - comment_at text not null, 1544 - body text not null, 1545 - created text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')), 1546 - repo_did text, 1547 - foreign key (repo_at, pull_id) references pulls(repo_at, pull_id) on delete cascade, 1548 - foreign key (submission_id) references pull_submissions(id) on delete cascade, 1549 - foreign key (repo_did) references repos(repo_did) on delete set null 1550 - ); 1551 - insert into pull_comments_fk (id, pull_id, submission_id, repo_at, owner_did, comment_at, body, created, repo_did) 1552 - select id, pull_id, submission_id, repo_at, owner_did, comment_at, body, created, repo_did from pull_comments; 1553 - drop table pull_comments; 1554 - alter table pull_comments_fk rename to pull_comments; 1555 - create index if not exists idx_pull_comments_repo_did on pull_comments(repo_did); 1556 - 1557 - -- pipelines: add FK on repo_did 1558 - create table pipelines_fk ( 1559 - id integer primary key autoincrement, 1560 - knot text not null, 1561 - rkey text not null, 1562 - repo_owner text not null, 1563 - repo_name text not null, 1564 - sha text not null check (length(sha) = 40), 1565 - created text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')), 1566 - trigger_id integer not null, 1567 - repo_did text, 1568 - unique(knot, rkey), 1569 - foreign key (trigger_id) references triggers(id) on delete cascade, 1570 - foreign key (repo_did) references repos(repo_did) on delete set null 1571 - ); 1572 - insert into pipelines_fk (id, knot, rkey, repo_owner, repo_name, sha, created, trigger_id, repo_did) 1573 - select id, knot, rkey, repo_owner, repo_name, sha, created, trigger_id, repo_did from pipelines; 1574 - drop table pipelines; 1575 - alter table pipelines_fk rename to pipelines; 1576 - create index if not exists idx_pipelines_repo_did on pipelines(repo_did); 1577 - 1578 - -- profile_pinned_repositories: add FK on repo_did 1579 - create table profile_pinned_repositories_fk ( 1580 - id integer primary key autoincrement, 1581 - did text not null, 1582 - at_uri text not null, 1583 - repo_did text, 1584 - unique(did, at_uri), 1585 - foreign key (did) references profile(did) on delete cascade, 1586 - foreign key (at_uri) references repos(at_uri) on delete cascade, 1587 - foreign key (repo_did) references repos(repo_did) on delete set null 1588 - ); 1589 - insert into profile_pinned_repositories_fk (id, did, at_uri, repo_did) 1590 - select id, did, at_uri, repo_did from profile_pinned_repositories; 1591 - drop table profile_pinned_repositories; 1592 - alter table profile_pinned_repositories_fk rename to profile_pinned_repositories; 1593 - `) 1594 - return err 1595 - }) 1596 - conn.ExecContext(ctx, "pragma foreign_keys = on;") 1597 - 1598 - orm.RunMigration(conn, logger, "add-source-repo-did-to-pulls", func(tx *sql.Tx) error { 1599 - _, err := tx.Exec(`alter table pulls add column source_repo_did text;`) 1600 - return err 1601 - }) 1602 - 1603 1324 orm.RunMigration(conn, logger, "migrate-knots-to-repo-dids", func(tx *sql.Tx) error { 1604 1325 _, err := tx.Exec(`update registrations set needs_upgrade = 1`) 1605 1326 return err
-1
appview/models/artifact.go
··· 16 16 Rkey string 17 17 18 18 RepoAt syntax.ATURI 19 - RepoDid string 20 19 Tag plumbing.Hash 21 20 CreatedAt time.Time 22 21
-1
appview/models/collaborator.go
··· 15 15 // content 16 16 SubjectDid syntax.DID 17 17 RepoAt syntax.ATURI 18 - RepoDid string 19 18 20 19 // meta 21 20 Created time.Time
+2 -17
appview/models/issue.go
··· 14 14 Did string 15 15 Rkey string 16 16 RepoAt syntax.ATURI 17 - RepoDid string 18 17 IssueId int 19 18 Created time.Time 20 19 Edited *time.Time ··· 45 44 for i, uri := range i.References { 46 45 references[i] = string(uri) 47 46 } 48 - var repo *string 49 - var repoDid *string 50 - if i.RepoDid != "" { 51 - repoDid = &i.RepoDid 52 - } else { 53 - s := i.RepoAt.String() 54 - repo = &s 55 - } 47 + repoAtStr := i.RepoAt.String() 56 48 return tangled.RepoIssue{ 57 - Repo: repo, 58 - RepoDid: repoDid, 49 + Repo: &repoAtStr, 59 50 Title: i.Title, 60 51 Body: &i.Body, 61 52 Mentions: mentions, ··· 176 167 repoAt = syntax.ATURI(*record.Repo) 177 168 } 178 169 179 - repoDid := "" 180 - if record.RepoDid != nil { 181 - repoDid = *record.RepoDid 182 - } 183 - 184 170 return Issue{ 185 171 RepoAt: repoAt, 186 - RepoDid: repoDid, 187 172 Did: did, 188 173 Rkey: rkey, 189 174 Created: created,
-1
appview/models/language.go
··· 7 7 type RepoLanguage struct { 8 8 Id int64 9 9 RepoAt syntax.ATURI 10 - RepoDid string 11 10 Ref string 12 11 IsDefaultRef bool 13 12 Language string
appview/models/pipeline.go

This file has not been changed.

+6 -19
appview/models/pull.go
··· 59 59 RepoAt syntax.ATURI 60 60 OwnerDid string 61 61 Rkey string 62 - RepoDid string 63 62 64 63 // content 65 64 Title string ··· 91 90 source = &tangled.RepoPull_Source{} 92 91 source.Branch = p.PullSource.Branch 93 92 source.Sha = p.LatestSha() 94 - if p.PullSource.RepoDid != "" { 95 - source.RepoDid = &p.PullSource.RepoDid 96 - } else if p.PullSource.RepoAt != nil { 93 + if p.PullSource.RepoAt != nil { 97 94 s := p.PullSource.RepoAt.String() 98 95 source.Repo = &s 99 96 } ··· 107 104 references[i] = string(uri) 108 105 } 109 106 110 - var targetRepo *string 111 - var targetRepoDid *string 112 - if p.RepoDid != "" { 113 - targetRepoDid = &p.RepoDid 114 - } else { 115 - s := p.RepoAt.String() 116 - targetRepo = &s 117 - } 107 + targetRepoStr := p.RepoAt.String() 118 108 record := tangled.RepoPull{ 119 109 Title: p.Title, 120 110 Body: &p.Body, ··· 122 112 References: references, 123 113 CreatedAt: p.Created.Format(time.RFC3339), 124 114 Target: &tangled.RepoPull_Target{ 125 - Repo: targetRepo, 126 - RepoDid: targetRepoDid, 127 - Branch: p.TargetBranch, 115 + Repo: &targetRepoStr, 116 + Branch: p.TargetBranch, 128 117 }, 129 118 Source: source, 130 119 } ··· 132 121 } 133 122 134 123 type PullSource struct { 135 - Branch string 136 - RepoAt *syntax.ATURI 137 - RepoDid string 124 + Branch string 125 + RepoAt *syntax.ATURI 138 126 139 127 // optionally populate this for reverse mappings 140 128 Repo *Repo ··· 168 156 RepoAt string 169 157 OwnerDid string 170 158 CommentAt string 171 - RepoDid string 172 159 173 160 // content 174 161 Body string
-1
appview/models/repo.go
··· 108 108 Id int64 109 109 RepoAt syntax.ATURI 110 110 LabelAt syntax.ATURI 111 - RepoDid string 112 111 } 113 112 114 113 type RepoGroup struct {
+4 -5
appview/models/star.go
··· 7 7 ) 8 8 9 9 type Star struct { 10 + Did string 11 + RepoAt syntax.ATURI 12 + Created time.Time 13 + Rkey string 10 - Did string 11 - RepoAt syntax.ATURI 12 - SubjectDid string 13 - Created time.Time 14 - Rkey string 15 14 } 16 15 17 16 // RepoStar is used for reverse mapping to repos
-1
appview/models/webhook.go
··· 16 16 type Webhook struct { 17 17 Id int64 18 18 RepoAt syntax.ATURI 19 - RepoDid string 20 19 Url string 21 20 Secret string 22 21 Active bool
+21 -2
appview/db/pipeline.go
··· 1 1 package db 2 2 3 3 import ( 4 + "database/sql" 4 5 "fmt" 5 6 "slices" 6 7 "strings" ··· 26 27 whereClause = " where " + strings.Join(conditions, " and ") 27 28 } 28 29 29 - query := fmt.Sprintf(`select id, rkey, knot, repo_owner, repo_name, sha, created from pipelines %s`, whereClause) 30 + query := fmt.Sprintf(`select id, rkey, knot, repo_owner, repo_name, sha, created, repo_did from pipelines %s`, whereClause) 30 31 31 32 rows, err := e.Query(query, args...) 32 33 ··· 38 39 for rows.Next() { 39 40 var pipeline models.Pipeline 40 41 var createdAt string 42 + var repoDid sql.NullString 41 43 err = rows.Scan( 42 44 &pipeline.Id, 43 45 &pipeline.Rkey, ··· 46 48 &pipeline.RepoName, 47 49 &pipeline.Sha, 48 50 &createdAt, 51 + &repoDid, 49 52 ) 50 53 if err != nil { 51 54 return nil, err ··· 54 57 if t, err := time.Parse(time.RFC3339, createdAt); err == nil { 55 58 pipeline.Created = t 56 59 } 60 + if repoDid.Valid { 61 + pipeline.RepoDid = repoDid.String 62 + } 57 63 58 64 pipelines = append(pipelines, pipeline) 59 65 } ··· 66 72 } 67 73 68 74 func AddPipeline(e Execer, pipeline models.Pipeline) error { 75 + var repoDid *string 76 + if pipeline.RepoDid != "" { 77 + repoDid = &pipeline.RepoDid 78 + } 79 + 69 80 args := []any{ 70 81 pipeline.Rkey, 71 82 pipeline.Knot, ··· 73 84 pipeline.RepoName, 74 85 pipeline.TriggerId, 75 86 pipeline.Sha, 87 + repoDid, 76 88 } 77 89 78 90 placeholders := make([]string, len(args)) ··· 87 99 repo_owner, 88 100 repo_name, 89 101 trigger_id, 90 - sha 102 + sha, 103 + repo_did 91 104 ) values (%s) 92 105 `, strings.Join(placeholders, ",")) 93 106 ··· 195 208 p.repo_name, 196 209 p.sha, 197 210 p.created, 211 + p.repo_did, 198 212 t.id, 199 213 t.kind, 200 214 t.push_ref, ··· 224 238 var p models.Pipeline 225 239 var t models.Trigger 226 240 var created string 241 + var repoDid sql.NullString 227 242 228 243 err := rows.Scan( 229 244 &p.Id, ··· 233 248 &p.RepoName, 234 249 &p.Sha, 235 250 &created, 251 + &repoDid, 236 252 &p.TriggerId, 237 253 &t.Kind, 238 254 &t.PushRef, ··· 251 267 if err != nil { 252 268 return nil, fmt.Errorf("invalid pipeline created timestamp %q: %w", created, err) 253 269 } 270 + if repoDid.Valid { 271 + p.RepoDid = repoDid.String 272 + } 254 273 255 274 t.Id = p.TriggerId 256 275 p.Trigger = &t
+1 -1
appview/db/pulls.go
··· 614 614 615 615 func SetPullState(e Execer, repoAt syntax.ATURI, pullId int, pullState models.PullState) error { 616 616 _, err := e.Exec( 617 - `update pulls set state = ? where repo_at = ? and pull_id = ? and (state <> ? or state <> ?)`, 617 + `update pulls set state = ? where repo_at = ? and pull_id = ? and (state <> ? and state <> ?)`, 618 618 pullState, 619 619 repoAt, 620 620 pullId,
+67 -15
appview/db/repos.go
··· 46 46 website, 47 47 topics, 48 48 source, 49 - spindle 49 + spindle, 50 + repo_did 50 51 from 51 52 repos r 52 53 %s ··· 64 65 for rows.Next() { 65 66 var repo models.Repo 66 67 var createdAt string 67 - var description, website, topicStr, source, spindle sql.NullString 68 + var description, website, topicStr, source, spindle, repoDid sql.NullString 68 69 69 70 err := rows.Scan( 70 71 &repo.Id, ··· 78 79 &topicStr, 79 80 &source, 80 81 &spindle, 82 + &repoDid, 81 83 ) 82 84 if err != nil { 83 85 return nil, fmt.Errorf("failed to execute repo query: %w ", err) ··· 101 103 if spindle.Valid { 102 104 repo.Spindle = spindle.String 103 105 } 106 + if repoDid.Valid { 107 + repo.RepoDid = repoDid.String 108 + } 104 109 105 110 repo.RepoStats = &models.RepoStats{} 106 111 repoMap[repo.RepoAt()] = &repo ··· 185 190 } 186 191 187 192 starCountQuery := fmt.Sprintf( 188 - `select 189 - subject_at, count(1) 193 + `select subject_at, count(1) 190 194 from stars 191 195 where subject_at in (%s) 192 196 group by subject_at`, ··· 352 356 var nullableDescription sql.NullString 353 357 var nullableWebsite sql.NullString 354 358 var nullableTopicStr sql.NullString 359 + var nullableRepoDid sql.NullString 360 + var nullableSource sql.NullString 361 + var nullableSpindle sql.NullString 355 362 356 - row := e.QueryRow(`select id, did, name, knot, created, rkey, description, website, topics from repos where at_uri = ?`, atUri) 363 + row := e.QueryRow(`select id, did, name, knot, created, rkey, description, website, topics, source, spindle, repo_did from repos where at_uri = ?`, atUri) 357 364 358 365 var createdAt string 359 - if err := row.Scan(&repo.Id, &repo.Did, &repo.Name, &repo.Knot, &createdAt, &repo.Rkey, &nullableDescription, &nullableWebsite, &nullableTopicStr); err != nil { 366 + if err := row.Scan(&repo.Id, &repo.Did, &repo.Name, &repo.Knot, &createdAt, &repo.Rkey, &nullableDescription, &nullableWebsite, &nullableTopicStr, &nullableSource, &nullableSpindle, &nullableRepoDid); err != nil { 360 367 return nil, err 361 368 } 362 369 createdAtTime, _ := time.Parse(time.RFC3339, createdAt) ··· 371 378 if nullableTopicStr.Valid { 372 379 repo.Topics = strings.Fields(nullableTopicStr.String) 373 380 } 381 + if nullableSource.Valid { 382 + repo.Source = nullableSource.String 383 + } 384 + if nullableSpindle.Valid { 385 + repo.Spindle = nullableSpindle.String 386 + } 387 + if nullableRepoDid.Valid { 388 + repo.RepoDid = nullableRepoDid.String 389 + } 374 390 375 391 return &repo, nil 376 392 } 377 393 378 394 func PutRepo(tx *sql.Tx, repo models.Repo) error { 395 + var repoDid *string 396 + if repo.RepoDid != "" { 397 + repoDid = &repo.RepoDid 398 + } 379 399 _, err := tx.Exec( 380 400 `update repos 381 - set knot = ?, description = ?, website = ?, topics = ? 401 + set knot = ?, description = ?, website = ?, topics = ?, repo_did = coalesce(?, repo_did) 382 402 where did = ? and rkey = ? 383 403 `, 384 - repo.Knot, repo.Description, repo.Website, repo.TopicStr(), repo.Did, repo.Rkey, 404 + repo.Knot, repo.Description, repo.Website, repo.TopicStr(), repoDid, repo.Did, repo.Rkey, 385 405 ) 386 406 return err 387 407 } 388 408 389 409 func AddRepo(tx *sql.Tx, repo *models.Repo) error { 410 + var repoDid *string 411 + if repo.RepoDid != "" { 412 + repoDid = &repo.RepoDid 413 + } 390 414 _, err := tx.Exec( 391 415 `insert into repos 392 - (did, name, knot, rkey, at_uri, description, website, topics, source) 393 - values (?, ?, ?, ?, ?, ?, ?, ?, ?)`, 394 - repo.Did, repo.Name, repo.Knot, repo.Rkey, repo.RepoAt().String(), repo.Description, repo.Website, repo.TopicStr(), repo.Source, 416 + (did, name, knot, rkey, at_uri, description, website, topics, source, repo_did) 417 + values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, 418 + repo.Did, repo.Name, repo.Knot, repo.Rkey, repo.RepoAt().String(), repo.Description, repo.Website, repo.TopicStr(), repo.Source, repoDid, 395 419 ) 396 420 if err != nil { 397 421 return fmt.Errorf("failed to insert repo: %w", err) ··· 431 455 if err != nil { 432 456 return nil, err 433 457 } 458 + if strings.HasPrefix(source, "did:") { 459 + return GetRepoByDid(e, source) 460 + } 434 461 return GetRepoByAtUri(e, source) 435 462 } 436 463 ··· 438 465 var repos []models.Repo 439 466 440 467 rows, err := e.Query( 441 - `select distinct r.id, r.did, r.name, r.knot, r.rkey, r.description, r.website, r.created, r.source 468 + `select distinct r.id, r.did, r.name, r.knot, r.rkey, r.description, r.website, r.created, r.source, r.repo_did 442 469 from repos r 443 470 left join collaborators c on r.at_uri = c.repo_at 444 471 where (r.did = ? or c.subject_did = ?) ··· 458 485 var nullableDescription sql.NullString 459 486 var nullableWebsite sql.NullString 460 487 var nullableSource sql.NullString 488 + var nullableRepoDid sql.NullString 461 489 462 - err := rows.Scan(&repo.Id, &repo.Did, &repo.Name, &repo.Knot, &repo.Rkey, &nullableDescription, &nullableWebsite, &createdAt, &nullableSource) 490 + err := rows.Scan(&repo.Id, &repo.Did, &repo.Name, &repo.Knot, &repo.Rkey, &nullableDescription, &nullableWebsite, &createdAt, &nullableSource, &nullableRepoDid) 463 491 if err != nil { 464 492 return nil, err 465 493 } ··· 467 495 if nullableDescription.Valid { 468 496 repo.Description = nullableDescription.String 469 497 } 498 + if nullableWebsite.Valid { 499 + repo.Website = nullableWebsite.String 500 + } 470 501 471 502 if nullableSource.Valid { 472 503 repo.Source = nullableSource.String 473 504 } 505 + if nullableRepoDid.Valid { 506 + repo.RepoDid = nullableRepoDid.String 507 + } 474 508 475 509 createdAtTime, err := time.Parse(time.RFC3339, createdAt) 476 510 if err != nil { ··· 496 530 var nullableWebsite sql.NullString 497 531 var nullableTopicStr sql.NullString 498 532 var nullableSource sql.NullString 533 + var nullableRepoDid sql.NullString 499 534 500 535 row := e.QueryRow( 501 - `select id, did, name, knot, rkey, description, website, topics, created, source 536 + `select id, did, name, knot, rkey, description, website, topics, created, source, repo_did 502 537 from repos 503 538 where did = ? and name = ? and source is not null and source != ''`, 504 539 did, name, 505 540 ) 506 541 507 - err := row.Scan(&repo.Id, &repo.Did, &repo.Name, &repo.Knot, &repo.Rkey, &nullableDescription, &nullableWebsite, &nullableTopicStr, &createdAt, &nullableSource) 542 + err := row.Scan(&repo.Id, &repo.Did, &repo.Name, &repo.Knot, &repo.Rkey, &nullableDescription, &nullableWebsite, &nullableTopicStr, &createdAt, &nullableSource, &nullableRepoDid) 508 543 if err != nil { 509 544 return nil, err 510 545 } ··· 524 559 if nullableSource.Valid { 525 560 repo.Source = nullableSource.String 526 561 } 562 + if nullableRepoDid.Valid { 563 + repo.RepoDid = nullableRepoDid.String 564 + } 527 565 528 566 createdAtTime, err := time.Parse(time.RFC3339, createdAt) 529 567 if err != nil { ··· 535 573 return &repo, nil 536 574 } 537 575 576 + func GetRepoByDid(e Execer, repoDid string) (*models.Repo, error) { 577 + return GetRepo(e, orm.FilterEq("repo_did", repoDid)) 578 + } 579 + 580 + func EnqueuePdsRewrite(e Execer, userDid, repoDid, recordNsid, recordRkey, oldRepoAt string) error { 581 + _, err := e.Exec( 582 + `INSERT OR IGNORE INTO pds_rewrite_status 583 + (user_did, repo_did, record_nsid, record_rkey, old_repo_at, status) 584 + VALUES (?, ?, ?, ?, ?, 'pending')`, 585 + userDid, repoDid, recordNsid, recordRkey, oldRepoAt, 586 + ) 587 + return err 588 + } 589 + 538 590 func UpdateDescription(e Execer, repoAt, newDescription string) error { 539 591 _, err := e.Exec( 540 592 `update repos set description = ? where at_uri = ?`, newDescription, repoAt)
+2 -1
appview/db/star.go
··· 66 66 func GetStarCount(e Execer, subjectAt syntax.ATURI) (int, error) { 67 67 stars := 0 68 68 err := e.QueryRow( 69 - `select count(did) from stars where subject_at = ?`, subjectAt).Scan(&stars) 69 + `select count(did) from stars where subject_at = ?`, 70 + subjectAt.String()).Scan(&stars) 70 71 if err != nil { 71 72 return 0, err 72 73 }
+2 -2
appview/pages/funcmap.go
··· 80 80 "ownerSlashRepo": func(repo *models.Repo) string { 81 81 ownerId, err := p.resolver.ResolveIdent(context.Background(), repo.Did) 82 82 if err != nil { 83 - return repo.DidSlashRepo() 83 + return repo.RepoIdentifier() 84 84 } 85 85 handle := ownerId.Handle 86 86 if handle != "" && !handle.IsInvalidHandle() { 87 87 return string(handle) + "/" + repo.Name 88 88 } 89 - return repo.DidSlashRepo() 89 + return repo.RepoIdentifier() 90 90 }, 91 91 "truncateAt30": func(s string) string { 92 92 if len(s) <= 30 {
+1 -1
appview/strings/strings.go
··· 149 149 showRendered = r.URL.Query().Get("code") != "true" 150 150 } 151 151 152 - starCount, err := db.GetStarCount(s.Db, string.AtUri()) 152 + starCount, err := db.GetStarCount(s.Db, "", string.AtUri()) 153 153 if err != nil { 154 154 l.Error("failed to get star count", "err", err) 155 155 }

History

12 rounds 1 comment
sign up or login to add to the discussion
1 commit
expand
appview: add repo_did to repos/stars/pipelines tables, update queries
merge conflicts detected
expand
  • go.mod:34
  • go.sum:339
expand 0 comments
1 commit
expand
appview: add repo_did to repos/stars/pipelines tables, update queries
expand 0 comments
1 commit
expand
appview: add repo_did to repos/stars/pipelines tables, update queries
expand 1 comment
1 commit
expand
appview: add repo_did columns, migrations, and model struct fields
expand 0 comments
1 commit
expand
appview: add repo_did columns, migrations, and model struct fields
expand 0 comments
1 commit
expand
appview: add repo_did columns, migrations, and model struct fields
expand 0 comments
1 commit
expand
appview: add repo_did columns, migrations, and model struct fields
expand 0 comments
1 commit
expand
appview: add repo_did columns, migrations, and model struct fields
expand 0 comments
1 commit
expand
appview: add repo_did columns, migrations, and model struct fields
expand 0 comments
1 commit
expand
appview: add repo_did columns, migrations, and model struct fields
expand 0 comments
1 commit
expand
appview: add repo_did columns, migrations, and model struct fields
expand 0 comments
1 commit
expand
appview: add repo_did columns, migrations, and model struct fields
expand 0 comments