fix(commits): set source on ingest/backfill writes, tidy Task 1 review findings

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
Dave 2026-09-19 10:22:26 +02:00
parent 65b09170af
commit 4d1e6cf412
3 changed files with 8 additions and 5 deletions

View file

@ -99,6 +99,7 @@ async function main() {
deletions: commit.stats?.deletions ?? 0,
link_source: "none",
url: commit.html_url,
source: "git",
});
created += 1;
}

View file

@ -233,7 +233,7 @@ async function ensureCommitSummaryFields(pb: PocketBase): Promise<void> {
* Re-runs are safe: fields are not duplicated, and backfill only touches rows
* where source is still unset.
*/
async function ensureManualEntryFields(pb: PocketBase): Promise<void> {
async function ensureCommitSourceFields(pb: PocketBase): Promise<void> {
const commits = await pb.collections.getOne("commits");
const have = new Set(commits.fields.map((f: { name: string }) => f.name));
@ -245,7 +245,7 @@ async function ensureManualEntryFields(pb: PocketBase): Promise<void> {
maxSelect: 1,
values: ["git", "manual"],
},
{ name: "manual_minutes", type: "number", required: false, onlyInt: true },
{ name: "manual_minutes", type: "number", required: false, onlyInt: true, min: 0 },
];
const fields = [...(commits.fields as unknown[])];
@ -262,7 +262,7 @@ async function ensureManualEntryFields(pb: PocketBase): Promise<void> {
await pb.collections.update(commits.id, { fields });
console.log(" + commits fields: source, manual_minutes");
} else {
console.log(" = manual entry fields already present");
console.log(" = commit source fields already present");
}
const unset = await pb.collection("commits").getFullList({
@ -272,7 +272,8 @@ async function ensureManualEntryFields(pb: PocketBase): Promise<void> {
for (const commit of unset) {
await pb.collection("commits").update(commit.id, { source: "git" });
}
console.log(` = commit source backfilled (${unset.length} row(s))`);
const prefix = unset.length > 0 ? "+" : "=";
console.log(` ${prefix} commit source backfilled (${unset.length} row(s))`);
}
/**
@ -999,7 +1000,7 @@ async function main(): Promise<void> {
await ensureCommitSummaryFields(pb);
// Add the source/manual_minutes fields for Phase 7's logged work entries.
await ensureManualEntryFields(pb);
await ensureCommitSourceFields(pb);
// Add the card number field and backfill existing cards.
await ensureCardNumbers(pb);

View file

@ -44,6 +44,7 @@ function toRecord(projectId: string, commit: ForgejoCommit) {
deletions: commit.stats?.deletions ?? 0,
link_source: "none" as const,
url: commit.html_url,
source: "git" as const,
};
}