···33import (
44 "context"
55 "database/sql"
66+ "fmt"
67 "log/slog"
78 "strings"
89···115116 issue_at text,
116117 unique(repo_at, issue_id),
117118 foreign key (repo_at) references repos(at_uri) on delete cascade
118118- );
119119- create table if not exists comments (
120120- id integer primary key autoincrement,
121121- owner_did text not null,
122122- issue_id integer not null,
123123- repo_at text not null,
124124- comment_id integer not null,
125125- comment_at text not null,
126126- body text not null,
127127- created text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
128128- unique(issue_id, comment_id),
129129- foreign key (repo_at, issue_id) references issues(repo_at, issue_id) on delete cascade
130119 );
131120 create table if not exists pulls (
132121 -- identifiers
···676665 create index if not exists idx_notifications_recipient_read on notifications(recipient_did, read);
677666 create index if not exists idx_references_from_at on reference_links(from_at);
678667 create index if not exists idx_references_to_at on reference_links(to_at);
679679- create index if not exists idx_webhooks_repo_at on webhooks(repo_at);
680668 create index if not exists idx_webhook_deliveries_webhook_id on webhook_deliveries(webhook_id);
681681- create index if not exists idx_site_deploys_repo_at on site_deploys(repo_at);
682669 create index if not exists idx_newsletter_prefs_user_did on newsletter_preferences(user_did);
683670 `)
684671 if err != nil {
···14741461 `)
14751462 return err
14761463 })
14641464+14651465+ orm.RunMigration(conn, logger, "add-repo-renames", func(tx *sql.Tx) error {
14661466+ res, err := tx.Exec(`
14671467+ update repos
14681468+ set name = name || '-renamed-' || id || '-' || lower(hex(randomblob(4)))
14691469+ where id in (
14701470+ select id from (
14711471+ select id, row_number() over (
14721472+ partition by did, knot, name
14731473+ order by created desc, id desc
14741474+ ) as rn
14751475+ from repos
14761476+ ) where rn > 1
14771477+ );
14781478+ `)
14791479+ if err != nil {
14801480+ return err
14811481+ }
14821482+ if n, _ := res.RowsAffected(); n > 0 {
14831483+ logger.Warn("suffixed legacy duplicate repo names before adding unique index", "rows", n)
14841484+ }
14851485+14861486+ var remaining int
14871487+ if err := tx.QueryRow(`
14881488+ select count(*) from (
14891489+ select 1 from repos group by did, knot, name having count(*) > 1
14901490+ )
14911491+ `).Scan(&remaining); err != nil {
14921492+ return fmt.Errorf("checking for residual duplicate (did, knot, name) groups: %w", err)
14931493+ }
14941494+ if remaining > 0 {
14951495+ return fmt.Errorf("add-repo-renames: %d duplicate (did, knot, name) groups remain after suffix pass; manual cleanup required before unique index can be created", remaining)
14961496+ }
14971497+14981498+ _, err = tx.Exec(`
14991499+ create table if not exists repo_renames (
15001500+ owner_did text not null,
15011501+ old_rkey text not null,
15021502+ repo_did text not null,
15031503+ renamed_at text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
15041504+ primary key (owner_did, old_rkey)
15051505+ );
15061506+ create unique index if not exists idx_repos_owner_knot_name
15071507+ on repos(did, knot, name);
15081508+ `)
15091509+ return err
15101510+ })
15111511+15121512+ orm.RunMigration(conn, logger, "repos-canonical-rkey-uniqueness", func(tx *sql.Tx) error {
15131513+ _, err := tx.Exec(`
15141514+ drop index if exists idx_repos_owner_knot_name;
15151515+ create unique index if not exists idx_repos_did_rkey
15161516+ on repos(did, rkey);
15171517+ `)
15181518+ return err
15191519+ })
15201520+15211521+ orm.RunMigration(conn, logger, "repo-did-references", func(tx *sql.Tx) error {
15221522+ tables := []struct{ table, oldCol, newCol string }{
15231523+ {"issues", "repo_at", "repo_did"},
15241524+ {"pulls", "repo_at", "repo_did"},
15251525+ {"pull_comments", "repo_at", "repo_did"},
15261526+ {"stars", "subject_at", "subject_did"},
15271527+ {"artifacts", "repo_at", "repo_did"},
15281528+ {"webhooks", "repo_at", "repo_did"},
15291529+ {"repo_sites", "repo_at", "repo_did"},
15301530+ {"site_deploys", "repo_at", "repo_did"},
15311531+ {"collaborators", "repo_at", "repo_did"},
15321532+ {"repo_issue_seqs", "repo_at", "repo_did"},
15331533+ {"repo_pull_seqs", "repo_at", "repo_did"},
15341534+ {"repo_languages", "repo_at", "repo_did"},
15351535+ {"repo_labels", "repo_at", "repo_did"},
15361536+ }
15371537+15381538+ stmts := ""
15391539+ for _, t := range tables {
15401540+ stmts += fmt.Sprintf(
15411541+ `ALTER TABLE %s ADD COLUMN %s TEXT;
15421542+ UPDATE %s SET %s = (SELECT repos.repo_did FROM repos WHERE repos.at_uri = %s.%s);
15431543+ CREATE INDEX IF NOT EXISTS idx_%s_%s ON %s(%s);
15441544+ `, t.table, t.newCol, t.table, t.newCol, t.table, t.oldCol, t.table, t.newCol, t.table, t.newCol)
15451545+ }
15461546+15471547+ stmts += `ALTER TABLE pulls ADD COLUMN source_repo_did TEXT;
15481548+ UPDATE pulls SET source_repo_did = (SELECT repos.repo_did FROM repos WHERE repos.at_uri = pulls.source_repo_at);
15491549+15501550+ UPDATE profile_pinned_repositories SET pin = (
15511551+ SELECT repos.repo_did FROM repos WHERE repos.at_uri = profile_pinned_repositories.pin
15521552+ ) WHERE pin LIKE 'at://%'
15531553+ AND EXISTS (SELECT 1 FROM repos WHERE repos.at_uri = profile_pinned_repositories.pin AND repos.repo_did IS NOT NULL AND repos.repo_did != '');
15541554+ `
15551555+15561556+ _, err := tx.Exec(stmts)
15571557+ return err
15581558+ })
15591559+15601560+ orm.RunMigration(conn, logger, "backfill-pds-rewrites-star-issue-pull-collab", func(tx *sql.Tx) error {
15611561+ type source struct {
15621562+ userDidCol string
15631563+ table string
15641564+ nsid string
15651565+ fkCol string
15661566+ }
15671567+ sources := []source{
15681568+ {"did", "stars", "sh.tangled.feed.star", "subject_at"},
15691569+ {"did", "issues", "sh.tangled.repo.issue", "repo_at"},
15701570+ {"owner_did", "pulls", "sh.tangled.repo.pull", "repo_at"},
15711571+ {"did", "collaborators", "sh.tangled.repo.collaborator", "repo_at"},
15721572+ }
15731573+15741574+ for _, src := range sources {
15751575+ _, err := tx.Exec(fmt.Sprintf(`
15761576+ INSERT INTO pds_migration (name, did, collection, rkey, status)
15771577+ SELECT 'add-repo-did', t.%s, '%s', t.rkey, 'pending'
15781578+ FROM %s t
15791579+ JOIN repos r ON r.at_uri = t.%s
15801580+ WHERE r.repo_did IS NOT NULL AND r.repo_did != ''
15811581+ ON CONFLICT(name, did, collection, rkey) DO NOTHING
15821582+ `, src.userDidCol, src.nsid, src.table, src.fkCol))
15831583+ if err != nil {
15841584+ return fmt.Errorf("backfill pds rewrites for %s: %w", src.table, err)
15851585+ }
15861586+ }
15871587+15881588+ return nil
15891589+ })
15901590+15911591+ orm.RunMigration(conn, logger, "backfill-pds-rewrites-profiles", func(tx *sql.Tx) error {
15921592+ _, err := tx.Exec(`
15931593+ INSERT INTO pds_migration (name, did, collection, rkey, status)
15941594+ SELECT DISTINCT 'add-repo-did', pp.did, 'sh.tangled.actor.profile', 'self', 'pending'
15951595+ FROM profile_pinned_repositories pp
15961596+ JOIN repos r ON r.at_uri = pp.pin
15971597+ WHERE pp.pin LIKE 'at://%'
15981598+ AND r.repo_did IS NOT NULL AND r.repo_did != ''
15991599+ ON CONFLICT(name, did, collection, rkey) DO NOTHING
16001600+ `)
16011601+ if err != nil {
16021602+ return fmt.Errorf("backfill pds rewrites for profiles: %w", err)
16031603+ }
16041604+ return nil
16051605+ })
16061606+16071607+ conn.ExecContext(ctx, "pragma foreign_keys = off;")
16081608+ orm.RunMigration(conn, logger, "drop-old-at-uri-columns", func(tx *sql.Tx) error {
16091609+ _, err := tx.Exec(`
16101610+ CREATE TABLE repos_new (
16111611+ id INTEGER PRIMARY KEY AUTOINCREMENT,
16121612+ did TEXT NOT NULL,
16131613+ name TEXT NOT NULL,
16141614+ knot TEXT NOT NULL,
16151615+ rkey TEXT NOT NULL,
16161616+ at_uri TEXT NOT NULL UNIQUE,
16171617+ created TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
16181618+ description TEXT CHECK (length(description) <= 200),
16191619+ source TEXT,
16201620+ spindle TEXT,
16211621+ website TEXT,
16221622+ topics TEXT,
16231623+ repo_did TEXT,
16241624+ UNIQUE(did, rkey)
16251625+ );
16261626+ INSERT INTO repos_new (id, did, name, knot, rkey, at_uri, created, description, source, spindle, website, topics, repo_did)
16271627+ SELECT id, did, name, knot, rkey, at_uri, created, description, source, spindle, website, topics, repo_did
16281628+ FROM repos;
16291629+ DROP TABLE repos;
16301630+ ALTER TABLE repos_new RENAME TO repos;
16311631+ CREATE UNIQUE INDEX idx_repos_repo_did ON repos(repo_did);
16321632+ CREATE UNIQUE INDEX idx_repos_did_rkey ON repos(did, rkey);
16331633+16341634+ CREATE TABLE issues_new (
16351635+ id INTEGER PRIMARY KEY AUTOINCREMENT,
16361636+ did TEXT NOT NULL,
16371637+ rkey TEXT NOT NULL,
16381638+ at_uri TEXT GENERATED ALWAYS AS ('at://' || did || '/' || 'sh.tangled.repo.issue' || '/' || rkey) STORED,
16391639+ repo_did TEXT NOT NULL,
16401640+ issue_id INTEGER NOT NULL,
16411641+ title TEXT NOT NULL,
16421642+ body TEXT NOT NULL,
16431643+ open INTEGER NOT NULL DEFAULT 1,
16441644+ created TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
16451645+ edited TEXT,
16461646+ deleted TEXT,
16471647+ UNIQUE(did, rkey),
16481648+ UNIQUE(repo_did, issue_id),
16491649+ UNIQUE(at_uri),
16501650+ FOREIGN KEY (repo_did) REFERENCES repos(repo_did) ON DELETE CASCADE
16511651+ );
16521652+ INSERT INTO issues_new (id, did, rkey, repo_did, issue_id, title, body, open, created, edited, deleted)
16531653+ SELECT id, did, rkey, repo_did, issue_id, title, body, open, created, edited, deleted
16541654+ FROM issues WHERE repo_did IS NOT NULL AND repo_did != '';
16551655+ DROP TABLE issues;
16561656+ ALTER TABLE issues_new RENAME TO issues;
16571657+ CREATE INDEX idx_issues_repo_did ON issues(repo_did);
16581658+16591659+ CREATE TABLE pulls_new (
16601660+ id INTEGER PRIMARY KEY AUTOINCREMENT,
16611661+ pull_id INTEGER NOT NULL,
16621662+ at_uri TEXT GENERATED ALWAYS AS ('at://' || owner_did || '/' || 'sh.tangled.repo.pull' || '/' || rkey) STORED,
16631663+ repo_did TEXT NOT NULL,
16641664+ owner_did TEXT NOT NULL,
16651665+ rkey TEXT NOT NULL,
16661666+ title TEXT NOT NULL,
16671667+ body TEXT NOT NULL,
16681668+ target_branch TEXT NOT NULL,
16691669+ state INTEGER NOT NULL DEFAULT 0 CHECK (state IN (0, 1, 2, 3)),
16701670+ source_branch TEXT,
16711671+ source_repo_did TEXT,
16721672+ change_id TEXT,
16731673+ dependent_on TEXT,
16741674+ created TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
16751675+ UNIQUE(repo_did, pull_id),
16761676+ UNIQUE(at_uri),
16771677+ FOREIGN KEY (repo_did) REFERENCES repos(repo_did) ON DELETE CASCADE
16781678+ );
16791679+ INSERT INTO pulls_new (id, pull_id, repo_did, owner_did, rkey, title, body, target_branch, state, source_branch, source_repo_did, change_id, dependent_on, created)
16801680+ SELECT id, pull_id, repo_did, owner_did, rkey, title, body, target_branch, state, source_branch, source_repo_did, change_id, dependent_on, created
16811681+ FROM pulls WHERE repo_did IS NOT NULL AND repo_did != '';
16821682+ DROP TABLE pulls;
16831683+ ALTER TABLE pulls_new RENAME TO pulls;
16841684+ CREATE INDEX idx_pulls_repo_did ON pulls(repo_did);
16851685+ CREATE INDEX idx_pulls_source_repo_did ON pulls(source_repo_did);
16861686+16871687+ CREATE TABLE pull_comments_new (
16881688+ id INTEGER PRIMARY KEY AUTOINCREMENT,
16891689+ pull_id INTEGER NOT NULL,
16901690+ submission_id INTEGER NOT NULL,
16911691+ repo_did TEXT NOT NULL,
16921692+ owner_did TEXT NOT NULL,
16931693+ comment_at TEXT NOT NULL,
16941694+ body TEXT NOT NULL,
16951695+ created TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
16961696+ FOREIGN KEY (repo_did, pull_id) REFERENCES pulls(repo_did, pull_id) ON DELETE CASCADE,
16971697+ FOREIGN KEY (submission_id) REFERENCES pull_submissions(id) ON DELETE CASCADE
16981698+ );
16991699+ INSERT INTO pull_comments_new (id, pull_id, submission_id, repo_did, owner_did, comment_at, body, created)
17001700+ SELECT id, pull_id, submission_id, repo_did, owner_did, comment_at, body, created
17011701+ FROM pull_comments WHERE repo_did IS NOT NULL AND repo_did != '';
17021702+ DROP TABLE pull_comments;
17031703+ ALTER TABLE pull_comments_new RENAME TO pull_comments;
17041704+ CREATE INDEX idx_pull_comments_repo_did ON pull_comments(repo_did);
17051705+17061706+ CREATE TABLE stars_new (
17071707+ id INTEGER PRIMARY KEY AUTOINCREMENT,
17081708+ did TEXT NOT NULL,
17091709+ rkey TEXT NOT NULL,
17101710+ subject_type TEXT NOT NULL CHECK (subject_type IN ('repo', 'string')),
17111711+ subject TEXT NOT NULL,
17121712+ created TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
17131713+ UNIQUE(did, rkey),
17141714+ UNIQUE(did, subject)
17151715+ );
17161716+ INSERT INTO stars_new (id, did, rkey, subject_type, subject, created)
17171717+ SELECT id, did, rkey, 'repo', subject_did, created
17181718+ FROM stars
17191719+ WHERE subject_did IS NOT NULL AND subject_did != '';
17201720+ INSERT OR IGNORE INTO stars_new (id, did, rkey, subject_type, subject, created)
17211721+ SELECT id, did, rkey, 'string', subject_at, created
17221722+ FROM stars
17231723+ WHERE (subject_did IS NULL OR subject_did = '')
17241724+ AND subject_at LIKE 'at://%/sh.tangled.string/%';
17251725+ DROP TABLE stars;
17261726+ ALTER TABLE stars_new RENAME TO stars;
17271727+ CREATE INDEX idx_stars_subject ON stars(subject);
17281728+ CREATE INDEX idx_stars_subject_type ON stars(subject_type);
17291729+ CREATE INDEX idx_stars_created ON stars(created);
17301730+17311731+ CREATE TABLE collaborators_new (
17321732+ id INTEGER PRIMARY KEY AUTOINCREMENT,
17331733+ did TEXT NOT NULL,
17341734+ rkey TEXT,
17351735+ subject_did TEXT NOT NULL,
17361736+ repo_did TEXT NOT NULL,
17371737+ created TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
17381738+ UNIQUE(did, rkey),
17391739+ FOREIGN KEY (repo_did) REFERENCES repos(repo_did) ON DELETE CASCADE
17401740+ );
17411741+ INSERT INTO collaborators_new (id, did, rkey, subject_did, repo_did, created)
17421742+ SELECT id, did, NULLIF(rkey, ''), subject_did, repo_did, created
17431743+ FROM collaborators WHERE repo_did IS NOT NULL AND repo_did != '';
17441744+ DROP TABLE collaborators;
17451745+ ALTER TABLE collaborators_new RENAME TO collaborators;
17461746+ CREATE INDEX idx_collaborators_repo_did ON collaborators(repo_did);
17471747+17481748+ CREATE TABLE artifacts_new (
17491749+ id INTEGER PRIMARY KEY AUTOINCREMENT,
17501750+ did TEXT NOT NULL,
17511751+ rkey TEXT NOT NULL,
17521752+ repo_did TEXT NOT NULL,
17531753+ tag BINARY(20) NOT NULL,
17541754+ created TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
17551755+ blob_cid TEXT NOT NULL,
17561756+ name TEXT NOT NULL,
17571757+ size INTEGER NOT NULL DEFAULT 0,
17581758+ mimetype TEXT NOT NULL DEFAULT '*/*',
17591759+ UNIQUE(did, rkey),
17601760+ UNIQUE(repo_did, tag, name),
17611761+ FOREIGN KEY (repo_did) REFERENCES repos(repo_did) ON DELETE CASCADE
17621762+ );
17631763+ INSERT INTO artifacts_new (id, did, rkey, repo_did, tag, created, blob_cid, name, size, mimetype)
17641764+ SELECT id, did, rkey, repo_did, tag, created, blob_cid, name, size, mimetype
17651765+ FROM artifacts WHERE repo_did IS NOT NULL AND repo_did != '';
17661766+ DROP TABLE artifacts;
17671767+ ALTER TABLE artifacts_new RENAME TO artifacts;
17681768+ CREATE INDEX idx_artifacts_repo_did ON artifacts(repo_did);
17691769+17701770+ CREATE TABLE webhooks_new (
17711771+ id INTEGER PRIMARY KEY AUTOINCREMENT,
17721772+ repo_did TEXT NOT NULL,
17731773+ url TEXT NOT NULL,
17741774+ secret TEXT,
17751775+ active INTEGER NOT NULL DEFAULT 1,
17761776+ events TEXT NOT NULL,
17771777+ created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
17781778+ updated_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
17791779+ FOREIGN KEY (repo_did) REFERENCES repos(repo_did) ON DELETE CASCADE
17801780+ );
17811781+ INSERT INTO webhooks_new (id, repo_did, url, secret, active, events, created_at, updated_at)
17821782+ SELECT id, repo_did, url, secret, active, events, created_at, updated_at
17831783+ FROM webhooks WHERE repo_did IS NOT NULL AND repo_did != '';
17841784+ DROP TABLE webhooks;
17851785+ ALTER TABLE webhooks_new RENAME TO webhooks;
17861786+ CREATE INDEX idx_webhooks_repo_did ON webhooks(repo_did);
17871787+17881788+ CREATE TABLE repo_sites_new (
17891789+ id INTEGER PRIMARY KEY AUTOINCREMENT,
17901790+ repo_did TEXT NOT NULL UNIQUE,
17911791+ branch TEXT NOT NULL,
17921792+ dir TEXT NOT NULL DEFAULT '/',
17931793+ is_index INTEGER NOT NULL DEFAULT 0,
17941794+ created TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
17951795+ updated TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
17961796+ FOREIGN KEY (repo_did) REFERENCES repos(repo_did) ON DELETE CASCADE
17971797+ );
17981798+ INSERT INTO repo_sites_new (id, repo_did, branch, dir, is_index, created, updated)
17991799+ SELECT id, repo_did, branch, dir, is_index, created, updated
18001800+ FROM repo_sites WHERE repo_did IS NOT NULL AND repo_did != '';
18011801+ DROP TABLE repo_sites;
18021802+ ALTER TABLE repo_sites_new RENAME TO repo_sites;
18031803+18041804+ CREATE TABLE site_deploys_new (
18051805+ id INTEGER PRIMARY KEY AUTOINCREMENT,
18061806+ repo_did TEXT NOT NULL,
18071807+ branch TEXT NOT NULL,
18081808+ dir TEXT NOT NULL DEFAULT '/',
18091809+ commit_sha TEXT NOT NULL DEFAULT '',
18101810+ status TEXT NOT NULL CHECK (status IN ('success', 'failure')),
18111811+ trigger TEXT NOT NULL CHECK (trigger IN ('config_change', 'push')),
18121812+ error TEXT NOT NULL DEFAULT '',
18131813+ created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
18141814+ FOREIGN KEY (repo_did) REFERENCES repos(repo_did) ON DELETE CASCADE
18151815+ );
18161816+ INSERT INTO site_deploys_new (id, repo_did, branch, dir, commit_sha, status, trigger, error, created_at)
18171817+ SELECT id, repo_did, branch, dir, commit_sha, status, trigger, error, created_at
18181818+ FROM site_deploys WHERE repo_did IS NOT NULL AND repo_did != '';
18191819+ DROP TABLE site_deploys;
18201820+ ALTER TABLE site_deploys_new RENAME TO site_deploys;
18211821+ CREATE INDEX idx_site_deploys_repo_did ON site_deploys(repo_did);
18221822+18231823+ CREATE TABLE repo_issue_seqs_new (
18241824+ repo_did TEXT PRIMARY KEY,
18251825+ next_issue_id INTEGER NOT NULL DEFAULT 1,
18261826+ FOREIGN KEY (repo_did) REFERENCES repos(repo_did) ON DELETE CASCADE
18271827+ );
18281828+ INSERT INTO repo_issue_seqs_new (repo_did, next_issue_id)
18291829+ SELECT repo_did, next_issue_id
18301830+ FROM repo_issue_seqs WHERE repo_did IS NOT NULL AND repo_did != '';
18311831+ DROP TABLE repo_issue_seqs;
18321832+ ALTER TABLE repo_issue_seqs_new RENAME TO repo_issue_seqs;
18331833+18341834+ CREATE TABLE repo_pull_seqs_new (
18351835+ repo_did TEXT PRIMARY KEY,
18361836+ next_pull_id INTEGER NOT NULL DEFAULT 1,
18371837+ FOREIGN KEY (repo_did) REFERENCES repos(repo_did) ON DELETE CASCADE
18381838+ );
18391839+ INSERT INTO repo_pull_seqs_new (repo_did, next_pull_id)
18401840+ SELECT repo_did, next_pull_id
18411841+ FROM repo_pull_seqs WHERE repo_did IS NOT NULL AND repo_did != '';
18421842+ DROP TABLE repo_pull_seqs;
18431843+ ALTER TABLE repo_pull_seqs_new RENAME TO repo_pull_seqs;
18441844+18451845+ CREATE TABLE repo_languages_new (
18461846+ id INTEGER PRIMARY KEY AUTOINCREMENT,
18471847+ repo_did TEXT NOT NULL,
18481848+ ref TEXT NOT NULL,
18491849+ is_default_ref INTEGER NOT NULL DEFAULT 0,
18501850+ language TEXT NOT NULL,
18511851+ bytes INTEGER NOT NULL CHECK (bytes >= 0),
18521852+ UNIQUE(repo_did, ref, language),
18531853+ FOREIGN KEY (repo_did) REFERENCES repos(repo_did) ON DELETE CASCADE
18541854+ );
18551855+ INSERT INTO repo_languages_new (id, repo_did, ref, is_default_ref, language, bytes)
18561856+ SELECT id, repo_did, ref, is_default_ref, language, bytes
18571857+ FROM repo_languages WHERE repo_did IS NOT NULL AND repo_did != '';
18581858+ DROP TABLE repo_languages;
18591859+ ALTER TABLE repo_languages_new RENAME TO repo_languages;
18601860+18611861+ CREATE TABLE repo_labels_new (
18621862+ id INTEGER PRIMARY KEY AUTOINCREMENT,
18631863+ repo_did TEXT NOT NULL,
18641864+ label_at TEXT NOT NULL,
18651865+ UNIQUE(repo_did, label_at),
18661866+ FOREIGN KEY (repo_did) REFERENCES repos(repo_did) ON DELETE CASCADE
18671867+ );
18681868+ INSERT INTO repo_labels_new (id, repo_did, label_at)
18691869+ SELECT id, repo_did, label_at
18701870+ FROM repo_labels WHERE repo_did IS NOT NULL AND repo_did != '';
18711871+ DROP TABLE repo_labels;
18721872+ ALTER TABLE repo_labels_new RENAME TO repo_labels;
18731873+ `)
18741874+ return err
18751875+ })
18761876+ conn.ExecContext(ctx, "pragma foreign_keys = on;")
1477187714781878 return &DB{
14791879 db,
+1-1
appview/models/artifact.go
···1515 Did string
1616 Rkey string
17171818- RepoAt syntax.ATURI
1818+ RepoDid syntax.DID
1919 Tag plumbing.Hash
2020 CreatedAt time.Time
2121
+1-1
appview/models/collaborator.go
···14141515 // content
1616 SubjectDid syntax.DID
1717- RepoAt syntax.ATURI
1717+ RepoDid syntax.DID
18181919 // meta
2020 Created time.Time