Signed-off-by: Lewis lewis@tangled.org
+151
-22
Diff
round #16
+39
appview/db/db.go
+39
appview/db/db.go
···
1295
1295
return err
1296
1296
})
1297
1297
1298
+
orm.RunMigration(conn, logger, "add-repo-did-column", func(tx *sql.Tx) error {
1299
+
_, err := tx.Exec(`
1300
+
alter table repos add column repo_did text;
1301
+
create unique index if not exists idx_repos_repo_did on repos(repo_did);
1302
+
`)
1303
+
return err
1304
+
})
1305
+
1306
+
orm.RunMigration(conn, logger, "add-pds-rewrite-status", func(tx *sql.Tx) error {
1307
+
_, err := tx.Exec(`
1308
+
create table if not exists pds_rewrite_status (
1309
+
id integer primary key autoincrement,
1310
+
user_did text not null,
1311
+
repo_did text not null,
1312
+
record_nsid text not null,
1313
+
record_rkey text not null,
1314
+
old_repo_at text not null,
1315
+
status text not null default 'pending',
1316
+
updated_at text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
1317
+
unique(user_did, record_nsid, record_rkey)
1318
+
);
1319
+
create index if not exists idx_pds_rewrite_user on pds_rewrite_status(user_did, status);
1320
+
`)
1321
+
return err
1322
+
})
1323
+
1324
+
orm.RunMigration(conn, logger, "add-pipelines-repo-did", func(tx *sql.Tx) error {
1325
+
_, err := tx.Exec(`
1326
+
alter table pipelines add column repo_did text;
1327
+
create index if not exists idx_pipelines_repo_did on pipelines(repo_did);
1328
+
`)
1329
+
return err
1330
+
})
1331
+
1332
+
orm.RunMigration(conn, logger, "migrate-knots-to-repo-dids", func(tx *sql.Tx) error {
1333
+
_, err := tx.Exec(`update registrations set needs_upgrade = 1`)
1334
+
return err
1335
+
})
1336
+
1298
1337
return &DB{
1299
1338
db,
1300
1339
logger,
+21
-2
appview/db/pipeline.go
+21
-2
appview/db/pipeline.go
···
2
2
3
3
import (
4
4
"context"
5
+
"database/sql"
5
6
"fmt"
6
7
"slices"
7
8
"strings"
···
27
28
whereClause = " where " + strings.Join(conditions, " and ")
28
29
}
29
30
30
-
query := fmt.Sprintf(`select id, rkey, knot, repo_owner, repo_name, sha, created from pipelines %s`, whereClause)
31
+
query := fmt.Sprintf(`select id, rkey, knot, repo_owner, repo_name, sha, created, repo_did from pipelines %s`, whereClause)
31
32
32
33
rows, err := e.Query(query, args...)
33
34
···
39
40
for rows.Next() {
40
41
var pipeline models.Pipeline
41
42
var createdAt string
43
+
var repoDid sql.NullString
42
44
err = rows.Scan(
43
45
&pipeline.Id,
44
46
&pipeline.Rkey,
···
47
49
&pipeline.RepoName,
48
50
&pipeline.Sha,
49
51
&createdAt,
52
+
&repoDid,
50
53
)
51
54
if err != nil {
52
55
return nil, err
···
55
58
if t, err := time.Parse(time.RFC3339, createdAt); err == nil {
56
59
pipeline.Created = t
57
60
}
61
+
if repoDid.Valid {
62
+
pipeline.RepoDid = repoDid.String
63
+
}
58
64
59
65
pipelines = append(pipelines, pipeline)
60
66
}
···
67
73
}
68
74
69
75
func AddPipeline(e Execer, pipeline models.Pipeline) error {
76
+
var repoDid *string
77
+
if pipeline.RepoDid != "" {
78
+
repoDid = &pipeline.RepoDid
79
+
}
80
+
70
81
args := []any{
71
82
pipeline.Rkey,
72
83
pipeline.Knot,
···
74
85
pipeline.RepoName,
75
86
pipeline.TriggerId,
76
87
pipeline.Sha,
88
+
repoDid,
77
89
}
78
90
79
91
placeholders := make([]string, len(args))
···
88
100
repo_owner,
89
101
repo_name,
90
102
trigger_id,
91
-
sha
103
+
sha,
104
+
repo_did
92
105
) values (%s)
93
106
`, strings.Join(placeholders, ","))
94
107
···
196
209
p.repo_name,
197
210
p.sha,
198
211
p.created,
212
+
p.repo_did,
199
213
t.id,
200
214
t.kind,
201
215
t.push_ref,
···
225
239
var p models.Pipeline
226
240
var t models.Trigger
227
241
var created string
242
+
var repoDid sql.NullString
228
243
229
244
err := rows.Scan(
230
245
&p.Id,
···
234
249
&p.RepoName,
235
250
&p.Sha,
236
251
&created,
252
+
&repoDid,
237
253
&p.TriggerId,
238
254
&t.Kind,
239
255
&t.PushRef,
···
252
268
if err != nil {
253
269
return nil, fmt.Errorf("invalid pipeline created timestamp %q: %w", created, err)
254
270
}
271
+
if repoDid.Valid {
272
+
p.RepoDid = repoDid.String
273
+
}
255
274
256
275
t.Id = p.TriggerId
257
276
p.Trigger = &t
+1
-1
appview/db/pulls.go
+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,
+66
-13
appview/db/repos.go
+66
-13
appview/db/repos.go
···
50
50
website,
51
51
topics,
52
52
source,
53
-
spindle
53
+
spindle,
54
+
repo_did
54
55
from repos
55
56
%s
56
57
order by created desc
···
67
68
for rows.Next() {
68
69
var repo models.Repo
69
70
var createdAt string
70
-
var description, website, topicStr, source, spindle sql.NullString
71
+
var description, website, topicStr, source, spindle, repoDid sql.NullString
71
72
72
73
err := rows.Scan(
73
74
&repo.Id,
···
81
82
&topicStr,
82
83
&source,
83
84
&spindle,
85
+
&repoDid,
84
86
)
85
87
if err != nil {
86
88
return nil, err
···
107
109
if spindle.Valid {
108
110
repo.Spindle = spindle.String
109
111
}
112
+
if repoDid.Valid {
113
+
repo.RepoDid = repoDid.String
114
+
}
110
115
111
116
repo.RepoStats = &models.RepoStats{}
112
117
repoMap[repo.RepoAt()] = &repo
···
357
362
var nullableDescription sql.NullString
358
363
var nullableWebsite sql.NullString
359
364
var nullableTopicStr sql.NullString
365
+
var nullableRepoDid sql.NullString
366
+
var nullableSource sql.NullString
367
+
var nullableSpindle sql.NullString
360
368
361
-
row := e.QueryRow(`select id, did, name, knot, created, rkey, description, website, topics from repos where at_uri = ?`, atUri)
369
+
row := e.QueryRow(`select id, did, name, knot, created, rkey, description, website, topics, source, spindle, repo_did from repos where at_uri = ?`, atUri)
362
370
363
371
var createdAt string
364
-
if err := row.Scan(&repo.Id, &repo.Did, &repo.Name, &repo.Knot, &createdAt, &repo.Rkey, &nullableDescription, &nullableWebsite, &nullableTopicStr); err != nil {
372
+
if err := row.Scan(&repo.Id, &repo.Did, &repo.Name, &repo.Knot, &createdAt, &repo.Rkey, &nullableDescription, &nullableWebsite, &nullableTopicStr, &nullableSource, &nullableSpindle, &nullableRepoDid); err != nil {
365
373
return nil, err
366
374
}
367
375
createdAtTime, _ := time.Parse(time.RFC3339, createdAt)
···
376
384
if nullableTopicStr.Valid {
377
385
repo.Topics = strings.Fields(nullableTopicStr.String)
378
386
}
387
+
if nullableSource.Valid {
388
+
repo.Source = nullableSource.String
389
+
}
390
+
if nullableSpindle.Valid {
391
+
repo.Spindle = nullableSpindle.String
392
+
}
393
+
if nullableRepoDid.Valid {
394
+
repo.RepoDid = nullableRepoDid.String
395
+
}
379
396
380
397
return &repo, nil
381
398
}
382
399
383
400
func PutRepo(tx *sql.Tx, repo models.Repo) error {
401
+
var repoDid *string
402
+
if repo.RepoDid != "" {
403
+
repoDid = &repo.RepoDid
404
+
}
384
405
_, err := tx.Exec(
385
406
`update repos
386
-
set knot = ?, description = ?, website = ?, topics = ?
407
+
set knot = ?, description = ?, website = ?, topics = ?, repo_did = coalesce(?, repo_did)
387
408
where did = ? and rkey = ?
388
409
`,
389
-
repo.Knot, repo.Description, repo.Website, repo.TopicStr(), repo.Did, repo.Rkey,
410
+
repo.Knot, repo.Description, repo.Website, repo.TopicStr(), repoDid, repo.Did, repo.Rkey,
390
411
)
391
412
return err
392
413
}
393
414
394
415
func AddRepo(tx *sql.Tx, repo *models.Repo) error {
416
+
var repoDid *string
417
+
if repo.RepoDid != "" {
418
+
repoDid = &repo.RepoDid
419
+
}
395
420
_, err := tx.Exec(
396
421
`insert into repos
397
-
(did, name, knot, rkey, at_uri, description, website, topics, source)
398
-
values (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
399
-
repo.Did, repo.Name, repo.Knot, repo.Rkey, repo.RepoAt().String(), repo.Description, repo.Website, repo.TopicStr(), repo.Source,
422
+
(did, name, knot, rkey, at_uri, description, website, topics, source, repo_did)
423
+
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
424
+
repo.Did, repo.Name, repo.Knot, repo.Rkey, repo.RepoAt().String(), repo.Description, repo.Website, repo.TopicStr(), repo.Source, repoDid,
400
425
)
401
426
if err != nil {
402
427
return fmt.Errorf("failed to insert repo: %w", err)
···
436
461
if err != nil {
437
462
return nil, err
438
463
}
464
+
if strings.HasPrefix(source, "did:") {
465
+
return GetRepoByDid(e, source)
466
+
}
439
467
return GetRepoByAtUri(e, source)
440
468
}
441
469
···
443
471
var repos []models.Repo
444
472
445
473
rows, err := e.Query(
446
-
`select distinct r.id, r.did, r.name, r.knot, r.rkey, r.description, r.website, r.created, r.source
474
+
`select distinct r.id, r.did, r.name, r.knot, r.rkey, r.description, r.website, r.created, r.source, r.repo_did
447
475
from repos r
448
476
left join collaborators c on r.at_uri = c.repo_at
449
477
where (r.did = ? or c.subject_did = ?)
···
463
491
var nullableDescription sql.NullString
464
492
var nullableWebsite sql.NullString
465
493
var nullableSource sql.NullString
494
+
var nullableRepoDid sql.NullString
466
495
467
-
err := rows.Scan(&repo.Id, &repo.Did, &repo.Name, &repo.Knot, &repo.Rkey, &nullableDescription, &nullableWebsite, &createdAt, &nullableSource)
496
+
err := rows.Scan(&repo.Id, &repo.Did, &repo.Name, &repo.Knot, &repo.Rkey, &nullableDescription, &nullableWebsite, &createdAt, &nullableSource, &nullableRepoDid)
468
497
if err != nil {
469
498
return nil, err
470
499
}
···
472
501
if nullableDescription.Valid {
473
502
repo.Description = nullableDescription.String
474
503
}
504
+
if nullableWebsite.Valid {
505
+
repo.Website = nullableWebsite.String
506
+
}
475
507
476
508
if nullableSource.Valid {
477
509
repo.Source = nullableSource.String
478
510
}
511
+
if nullableRepoDid.Valid {
512
+
repo.RepoDid = nullableRepoDid.String
513
+
}
479
514
480
515
createdAtTime, err := time.Parse(time.RFC3339, createdAt)
481
516
if err != nil {
···
501
536
var nullableWebsite sql.NullString
502
537
var nullableTopicStr sql.NullString
503
538
var nullableSource sql.NullString
539
+
var nullableRepoDid sql.NullString
504
540
505
541
row := e.QueryRow(
506
-
`select id, did, name, knot, rkey, description, website, topics, created, source
542
+
`select id, did, name, knot, rkey, description, website, topics, created, source, repo_did
507
543
from repos
508
544
where did = ? and name = ? and source is not null and source != ''`,
509
545
did, name,
510
546
)
511
547
512
-
err := row.Scan(&repo.Id, &repo.Did, &repo.Name, &repo.Knot, &repo.Rkey, &nullableDescription, &nullableWebsite, &nullableTopicStr, &createdAt, &nullableSource)
548
+
err := row.Scan(&repo.Id, &repo.Did, &repo.Name, &repo.Knot, &repo.Rkey, &nullableDescription, &nullableWebsite, &nullableTopicStr, &createdAt, &nullableSource, &nullableRepoDid)
513
549
if err != nil {
514
550
return nil, err
515
551
}
···
529
565
if nullableSource.Valid {
530
566
repo.Source = nullableSource.String
531
567
}
568
+
if nullableRepoDid.Valid {
569
+
repo.RepoDid = nullableRepoDid.String
570
+
}
532
571
533
572
createdAtTime, err := time.Parse(time.RFC3339, createdAt)
534
573
if err != nil {
···
540
579
return &repo, nil
541
580
}
542
581
582
+
func GetRepoByDid(e Execer, repoDid string) (*models.Repo, error) {
583
+
return GetRepo(e, orm.FilterEq("repo_did", repoDid))
584
+
}
585
+
586
+
func EnqueuePdsRewrite(e Execer, userDid, repoDid, recordNsid, recordRkey, oldRepoAt string) error {
587
+
_, err := e.Exec(
588
+
`INSERT OR IGNORE INTO pds_rewrite_status
589
+
(user_did, repo_did, record_nsid, record_rkey, old_repo_at, status)
590
+
VALUES (?, ?, ?, ?, ?, 'pending')`,
591
+
userDid, repoDid, recordNsid, recordRkey, oldRepoAt,
592
+
)
593
+
return err
594
+
}
595
+
543
596
func UpdateDescription(e Execer, repoAt, newDescription string) error {
544
597
_, err := e.Exec(
545
598
`update repos set description = ? where at_uri = ?`, newDescription, repoAt)
+8
-2
appview/models/issue.go
+8
-2
appview/models/issue.go
···
44
44
for i, uri := range i.References {
45
45
references[i] = string(uri)
46
46
}
47
+
repoAtStr := i.RepoAt.String()
47
48
return tangled.RepoIssue{
48
-
Repo: i.RepoAt.String(),
49
+
Repo: &repoAtStr,
49
50
Title: i.Title,
50
51
Body: &i.Body,
51
52
Mentions: mentions,
···
161
162
body = *record.Body
162
163
}
163
164
165
+
var repoAt syntax.ATURI
166
+
if record.Repo != nil {
167
+
repoAt = syntax.ATURI(*record.Repo)
168
+
}
169
+
164
170
return Issue{
165
-
RepoAt: syntax.ATURI(record.Repo),
171
+
RepoAt: repoAt,
166
172
Did: did,
167
173
Rkey: rkey,
168
174
Created: created,
+1
appview/models/pipeline.go
+1
appview/models/pipeline.go
+2
-1
appview/models/pull.go
+2
-1
appview/models/pull.go
···
104
104
references[i] = string(uri)
105
105
}
106
106
107
+
targetRepoStr := p.RepoAt.String()
107
108
record := tangled.RepoPull{
108
109
Title: p.Title,
109
110
Body: &p.Body,
···
111
112
References: references,
112
113
CreatedAt: p.Created.Format(time.RFC3339),
113
114
Target: &tangled.RepoPull_Target{
114
-
Repo: p.RepoAt.String(),
115
+
Repo: &targetRepoStr,
115
116
Branch: p.TargetBranch,
116
117
},
117
118
Source: source,
+11
-1
appview/models/repo.go
+11
-1
appview/models/repo.go
···
22
22
Topics []string
23
23
Spindle string
24
24
Labels []string
25
+
RepoDid string
25
26
26
27
// optionally, populate this when querying for reverse mappings
27
28
RepoStats *RepoStats
···
49
50
website = &r.Website
50
51
}
51
52
53
+
var repoDid *string
54
+
if r.RepoDid != "" {
55
+
repoDid = &r.RepoDid
56
+
}
57
+
52
58
return tangled.Repo{
53
59
Knot: r.Knot,
54
60
Name: r.Name,
···
59
65
Source: source,
60
66
Spindle: spindle,
61
67
Labels: r.Labels,
68
+
RepoDid: repoDid,
62
69
}
63
70
}
64
71
···
66
73
return syntax.ATURI(fmt.Sprintf("at://%s/%s/%s", r.Did, tangled.RepoNSID, r.Rkey))
67
74
}
68
75
69
-
func (r Repo) DidSlashRepo() string {
76
+
func (r Repo) RepoIdentifier() string {
77
+
if r.RepoDid != "" {
78
+
return r.RepoDid
79
+
}
70
80
p, _ := securejoin.SecureJoin(r.Did, r.Name)
71
81
return p
72
82
}
+2
-2
appview/pages/funcmap.go
+2
-2
appview/pages/funcmap.go
···
84
84
"ownerSlashRepo": func(repo *models.Repo) string {
85
85
ownerId, err := p.resolver.ResolveIdent(context.Background(), repo.Did)
86
86
if err != nil {
87
-
return repo.DidSlashRepo()
87
+
return repo.RepoIdentifier()
88
88
}
89
89
handle := ownerId.Handle
90
90
if handle != "" && !handle.IsInvalidHandle() {
91
91
return string(handle) + "/" + repo.Name
92
92
}
93
-
return repo.DidSlashRepo()
93
+
return repo.RepoIdentifier()
94
94
},
95
95
"truncateAt30": func(s string) string {
96
96
if len(s) <= 30 {
History
17 rounds
1 comment
oyster.cafe
submitted
#16
1 commit
expand
collapse
appview: add repo_did to repos/stars/pipelines tables, update queries
Signed-off-by: Lewis <lewis@tangled.org>
expand 0 comments
pull request successfully merged
oyster.cafe
submitted
#15
1 commit
expand
collapse
appview: add repo_did to repos/stars/pipelines tables, update queries
Signed-off-by: Lewis <lewis@tangled.org>
expand 0 comments
oyster.cafe
submitted
#14
1 commit
expand
collapse
appview: add repo_did to repos/stars/pipelines tables, update queries
Signed-off-by: Lewis <lewis@tangled.org>
expand 0 comments
oyster.cafe
submitted
#13
1 commit
expand
collapse
appview: add repo_did to repos/stars/pipelines tables, update queries
Signed-off-by: Lewis <lewis@tangled.org>
expand 0 comments
oyster.cafe
submitted
#12
1 commit
expand
collapse
appview: add repo_did to repos/stars/pipelines tables, update queries
Signed-off-by: Lewis <lewis@tangled.org>
expand 0 comments
oyster.cafe
submitted
#11
1 commit
expand
collapse
appview: add repo_did to repos/stars/pipelines tables, update queries
Signed-off-by: Lewis <lewis@tangled.org>
expand 0 comments
oyster.cafe
submitted
#10
1 commit
expand
collapse
appview: add repo_did to repos/stars/pipelines tables, update queries
Signed-off-by: Lewis <lewis@tangled.org>
expand 0 comments
oyster.cafe
submitted
#9
1 commit
expand
collapse
appview: add repo_did to repos/stars/pipelines tables, update queries
Signed-off-by: Lewis <lewis@tangled.org>
expand 1 comment
oyster.cafe
submitted
#8
1 commit
expand
collapse
appview: add repo_did columns, migrations, and model struct fields
Signed-off-by: Lewis <lewis@tangled.org>
expand 0 comments
oyster.cafe
submitted
#7
1 commit
expand
collapse
appview: add repo_did columns, migrations, and model struct fields
Signed-off-by: Lewis <lewis@tangled.org>
expand 0 comments
oyster.cafe
submitted
#6
1 commit
expand
collapse
appview: add repo_did columns, migrations, and model struct fields
Signed-off-by: Lewis <lewis@tangled.org>
expand 0 comments
oyster.cafe
submitted
#5
1 commit
expand
collapse
appview: add repo_did columns, migrations, and model struct fields
Signed-off-by: Lewis <lewis@tangled.org>
expand 0 comments
oyster.cafe
submitted
#4
1 commit
expand
collapse
appview: add repo_did columns, migrations, and model struct fields
Signed-off-by: Lewis <lewis@tangled.org>
expand 0 comments
oyster.cafe
submitted
#3
1 commit
expand
collapse
appview: add repo_did columns, migrations, and model struct fields
Signed-off-by: Lewis <lewis@tangled.org>
expand 0 comments
oyster.cafe
submitted
#2
1 commit
expand
collapse
appview: add repo_did columns, migrations, and model struct fields
Signed-off-by: Lewis <lewis@tangled.org>
expand 0 comments
oyster.cafe
submitted
#1
1 commit
expand
collapse
appview: add repo_did columns, migrations, and model struct fields
Signed-off-by: Lewis <lewis@tangled.org>
expand 0 comments
oyster.cafe
submitted
#0
1 commit
expand
collapse
appview: add repo_did columns, migrations, and model struct fields
Signed-off-by: Lewis <lewis@tangled.org>
appview/db/star.go:69was there an issue here?appview/strings/strings.go:152seems to be a typo.GetStarCountreceives 2 arguments