From 677be8d82fec3dda7e39b6838439feac4e5be153 Mon Sep 17 00:00:00 2001 From: aiongg <67543387+aiongg@users.noreply.github.com> Date: Sat, 21 Nov 2026 22:59:45 +0000 Subject: [PATCH] Build the owner and pilot queries with Kysely: owners are read through the handle or a reader the connection supplies, trackedOwners and inPilot go through db.k --- src/db.ts | 8 +++--- src/owners.ts | 29 +++++++++----------- src/pilot.ts | 21 ++++++++------- test/outside-limits.test.ts | 12 ++++----- test/raw-sql-not-converted.txt | 2 -- test/repo-owners.test.ts | 5 ++-- test/sync-health.test.ts | 49 +++++++++++++++++++--------------- 7 files changed, 65 insertions(+), 61 deletions(-) diff --git a/src/db.ts b/src/db.ts index 45b6504d..cb8fa7e1 100644 --- a/src/db.ts +++ b/src/db.ts @@ -1,5 +1,5 @@ import { isBotCommand, isBotLogin } from "./review/bots.ts"; -import { loadOwners } from "./owners.ts"; +import { loadOwners, type OwnerRow } from "./owners.ts"; import { createHash } from "node:crypto"; import { mkdirSync, readFileSync } from "node:fs"; import { homedir } from "node:os"; @@ -716,6 +716,8 @@ function stampOf(db: DatabaseSync): string | null { } } +const ownerRows = (db: DatabaseSync): OwnerRow[] => db.prepare("SELECT name, owner FROM main.repos").all() as OwnerRow[]; + /** * Opens the database and brings its schema up to date. `busyTimeoutMs` replaces the 30-second busy timeout once the * schema is current: a connection that serves requests waits that long for a write lock, then throws SQLITE_BUSY. @@ -743,7 +745,7 @@ function open(path: string): DatabaseSync { // A current database takes no write lock here: opening a connection must not wait for a sync. if (stampOf(db) === stamp) { migrateValues(db); - loadOwners(db); + loadOwners(() => ownerRows(db)); return db; } db.exec(schema); @@ -774,6 +776,6 @@ function open(path: string): DatabaseSync { db.exec(`INSERT OR IGNORE INTO main.settings (key, value) SELECT 'tracking_started_at', COALESCE((SELECT MIN(synced_at) FROM main.repos), strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))`); db.prepare("INSERT INTO main.settings (key, value) VALUES ('schema_stamp', ?) ON CONFLICT (key) DO UPDATE SET value = excluded.value").run(stamp); - loadOwners(db); + loadOwners(() => ownerRows(db)); return db; } diff --git a/src/owners.ts b/src/owners.ts index b341bf0e..a6d6579f 100644 --- a/src/owners.ts +++ b/src/owners.ts @@ -1,37 +1,35 @@ // Owner (GitHub org or user) of each repo. Repo names are unique across owners, so items keep // the bare name as key; the owner is a property of the `repos` row. Repos without a row are storytold's. -// A structural type: the web build imports this module through the templates and has no node types. -type DatabaseSync = { prepare(sql: string): { all(...params: never[]): unknown[] } }; +import type { Db } from "./db/index.ts"; + +export type OwnerRow = { name: string; owner: string | null }; export const DEFAULT_OWNER = "storytold"; export const OWNER = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})$/; const REFRESH_MS = 30_000; let cache = new Map(); -let source: DatabaseSync | null = null; +let source: (() => OwnerRow[]) | null = null; let loadedAt = 0; // Counts loads. An async reload stores its rows only when no load started after it, so a reload whose read finished // late never puts back an older owner list. let loads = 0; -/** Reads the owners from the `repos` table; the most recently loaded database also refreshes the cache later. */ -export function loadOwners(db: DatabaseSync): void { - source = db; +/** Reads the owners with `read` (the rows of the `repos` table); the most recently loaded reader also refreshes the cache later. */ +export function loadOwners(read: () => OwnerRow[]): void { + source = read; loads++; - setOwners(db.prepare(OWNERS_SQL).all() as OwnerRow[]); + setOwners(read()); } /** loadOwners() through the async handle, after a write to `repos`. The cache refreshes later from the connection loaded last. */ -export async function reloadOwners(db: { prepare(sql: string): { all(...params: never[]): Promise } }): Promise { +export async function reloadOwners(db: Db): Promise { const mine = ++loads; - const rows = await db.prepare(OWNERS_SQL).all() as OwnerRow[]; + const rows = await db.all(db.k.selectFrom("main.repos").select(["name", "owner"])); if (mine === loads) setOwners(rows); } -const OWNERS_SQL = "SELECT name, owner FROM main.repos"; -type OwnerRow = { name: string; owner: string | null }; - function setOwners(rows: OwnerRow[]): void { const next = new Map(); for (const r of rows) if (r.owner) next.set(r.name, r.owner); @@ -62,10 +60,9 @@ export function splitSlug(s: string): { owner: string; name: string } { } /** Every owner with a tracked repo, plus the default one. */ -export function trackedOwners(db: DatabaseSync): string[] { - const rows = db.prepare( - "SELECT DISTINCT COALESCE(r.owner, ?) AS owner FROM main.tracked_repos t LEFT JOIN main.repos r ON r.name = t.name", - ).all(DEFAULT_OWNER as never) as { owner: string }[]; +export async function trackedOwners(db: Db): Promise { + const rows = await db.all(db.k.selectFrom("main.tracked_repos as t").leftJoin("main.repos as r", "r.name", "t.name") + .select((eb) => eb.fn.coalesce("r.owner", eb.val(DEFAULT_OWNER)).as("owner")).distinct()); return [...new Set([DEFAULT_OWNER, ...rows.map((r) => r.owner)])].sort(); } diff --git a/src/pilot.ts b/src/pilot.ts index 621633db..151df4ef 100644 --- a/src/pilot.ts +++ b/src/pilot.ts @@ -34,16 +34,16 @@ export async function pilotItems(db: Db): Promise { /** Tracked repos whose pipeline flag is on. */ export async function pipelineRepos(db: Db): Promise> { - return new Set((await db.prepare("SELECT name FROM main.tracked_repos WHERE pipeline = 1").all() as { name: string }[]).map((r) => r.name)); + return new Set((await db.all(db.k.selectFrom("main.tracked_repos").select("name").where("pipeline", "=", 1))).map((r) => r.name)); } export const pipelineOn = async (db: Db, repo: string): Promise => - await db.prepare("SELECT 1 FROM main.tracked_repos WHERE name = ? AND pipeline = 1").get(repo) !== undefined; + await db.get(db.k.selectFrom("main.tracked_repos").select("name").where("name", "=", repo).where("pipeline", "=", 1)) !== undefined; /** Sets a tracked repo's pipeline flag. Returns false when nothing changed. */ export async function setRepoPipeline(db: Db, by: string, repo: string, on: boolean): Promise { - if (!NAME.test(repo) || !await db.prepare("SELECT 1 FROM main.tracked_repos WHERE name = ?").get(repo)) throw new PilotError(`${repo} is not tracked`); - const changed = Number((await db.prepare("UPDATE main.tracked_repos SET pipeline = ? WHERE name = ? AND pipeline <> ?").run(on ? 1 : 0, repo, on ? 1 : 0)).changes) > 0; + if (!NAME.test(repo) || !await db.get(db.k.selectFrom("main.tracked_repos").select("name").where("name", "=", repo))) throw new PilotError(`${repo} is not tracked`); + const changed = (await db.run(db.k.updateTable("main.tracked_repos").set({ pipeline: on ? 1 : 0 }).where("name", "=", repo).where("pipeline", "<>", on ? 1 : 0))).changes > 0; if (changed) await audit(db, by, "repo-pipeline", repo, { on }); return changed; } @@ -59,8 +59,9 @@ export async function baseScopeRepos(db: Db): Promise> { export async function scopeRepos(db: Db): Promise> { const out = await baseScopeRepos(db); // A repo with a fast-tracked open item takes part for that item alone (see pilotSqlFor). - for (const r of await db.prepare(`SELECT DISTINCT f.repo FROM main.fast_track f JOIN main.tracked_repos t ON t.name = f.repo - JOIN main.items i ON i.repo = f.repo AND i.number = f.number AND i.state = 'OPEN'`).all() as { repo: string }[]) out.add(r.repo); + for (const r of await db.all(db.k.selectFrom("main.fast_track as f").innerJoin("main.tracked_repos as t", "t.name", "f.repo") + .innerJoin("main.items as i", (j) => j.onRef("i.repo", "=", "f.repo").onRef("i.number", "=", "f.number").on("i.state", "=", "OPEN")) + .select("f.repo").distinct())) out.add(r.repo); return out; } @@ -68,7 +69,7 @@ export async function scopeRepos(db: Db): Promise> { export async function parsePilotRefs(db: Db, input: unknown): Promise { const parts = Array.isArray(input) ? input : typeof input === "string" ? input.split(/[\s,]+/).filter(Boolean) : null; if (!parts || parts.some((p) => typeof p !== "string")) throw new PilotError("items must be a list of repo#number"); - const tracked = new Set((await db.prepare("SELECT name FROM main.tracked_repos").all() as { name: string }[]).map((r) => r.name)); + const tracked = new Set((await db.all(db.k.selectFrom("main.tracked_repos").select("name"))).map((r) => r.name)); const out: string[] = []; for (const p of parts as string[]) { const m = REF.exec(p); @@ -84,8 +85,8 @@ export async function parsePilotRefs(db: Db, input: unknown): Promise /** Replaces the list; an empty list clears the pilot. Returns the stored list. */ export async function setPilot(db: Db, by: string, input: unknown): Promise { const refs = await parsePilotRefs(db, input); - if (refs.length) await db.prepare("INSERT INTO main.settings (key, value) VALUES (?, ?) ON CONFLICT (key) DO UPDATE SET value = excluded.value").run(PILOT_KEY, JSON.stringify(refs)); - else await db.prepare("DELETE FROM main.settings WHERE key = ?").run(PILOT_KEY); + if (refs.length) await db.run(db.k.insertInto("main.settings").values({ key: PILOT_KEY, value: JSON.stringify(refs) }).onConflict((oc) => oc.column("key").doUpdateSet(kx.excluded(["value"])))); + else await db.run(db.k.deleteFrom("main.settings").where("key", "=", PILOT_KEY)); await audit(db, by, refs.length ? "pilot-set" : "pilot-clear", PILOT_KEY, { items: refs }); return refs; } @@ -149,5 +150,5 @@ export const pilotExpr = (db: Db, eb: kx.AnyEb, alias: string): AliasableExpress /** True when the item is in scope. */ export async function inPilot(db: Db, repo: string, number: number): Promise { - return !!await db.prepare(`SELECT 1 WHERE ${pilotSqlFor(db, "?1", "CAST(?2 AS INTEGER)")}`).get(repo, number); + return !!await db.get(db.k.selectNoFrom((eb) => eb.lit(1).as("one")).where((eb) => pilotExprFor(db, eb, eb.val(repo), eb.cast(eb.val(number), "bigint")))); } diff --git a/test/outside-limits.test.ts b/test/outside-limits.test.ts index 851f4e33..d07dc5a1 100644 --- a/test/outside-limits.test.ts +++ b/test/outside-limits.test.ts @@ -11,11 +11,11 @@ const ago = (min: number) => new Date(NOW - min * 60_000).toISOString(); async function setup() { const db = await connectDb(":memory:"); - await db.prepare("INSERT OR IGNORE INTO tracked_repos (name, pipeline) VALUES ('app', 1)").run(); - await db.prepare("INSERT INTO settings (key, value) VALUES ('pipeline_login', 'bot')").run(); + await db.run(db.k.insertInto("tracked_repos").values({ name: "app", pipeline: 1 }).onConflict((oc) => oc.doNothing())); + await db.run(db.k.insertInto("settings").values({ key: "pipeline_login", value: "bot" })); let n = 0; const add = async (author: string, kind: "pr" | "issue", minAgo: number, assoc = "NONE") => - await db.prepare("INSERT INTO items (repo, number, kind, state, author, author_association, created_at) VALUES ('app', ?, ?, 'OPEN', ?, ?, ?)").run(++n, kind, author, assoc, ago(minAgo)) && n; + await db.run(db.k.insertInto("items").values({ repo: "app", number: ++n, kind, state: "OPEN", author, author_association: assoc, created_at: ago(minAgo) })) && n; return { db, add }; } @@ -41,10 +41,10 @@ test("an outside author's 6th PR in 24 hours waits; members and the pipeline's o await setOutsideLimits(db, "op", { prsPerDay: 5 }); // Items of a repo whose pipeline is off are neither counted nor held. - await db.prepare("INSERT INTO tracked_repos (name, pipeline) VALUES ('idle', 0)").run(); - for (let k = 1; k <= 8; k++) await db.prepare("INSERT INTO items (repo, number, kind, state, author, author_association, created_at) VALUES ('idle', ?, 'pr', 'OPEN', 'offauthor', 'NONE', ?)").run(k, ago(50)); + await db.run(db.k.insertInto("tracked_repos").values({ name: "idle", pipeline: 0 })); + for (let k = 1; k <= 8; k++) await db.run(db.k.insertInto("items").values({ repo: "idle", number: k, kind: "pr", state: "OPEN", author: "offauthor", author_association: "NONE", created_at: ago(50) })); await refreshOutsideHolds(db, NOW); - assert.equal((await db.prepare("SELECT COUNT(*) AS n FROM outside_holds WHERE repo = 'idle'").get() as { n: number }).n, 0); + assert.equal((await db.get(db.k.selectFrom("outside_holds").select((eb) => eb.fn.countAll().as("n")).where("repo", "=", "idle")))!.n, 0); // The oldest items age out of the window: the held one starts by itself. const held = await add("outsider", "pr", 1); diff --git a/test/raw-sql-not-converted.txt b/test/raw-sql-not-converted.txt index 58a21aae..aa0375b3 100644 --- a/test/raw-sql-not-converted.txt +++ b/test/raw-sql-not-converted.txt @@ -343,11 +343,9 @@ src/optional-checks.ts src/outside.ts -src/owners.ts src/patchcheck/index.ts -src/pilot.ts src/postmerge/file.ts diff --git a/test/repo-owners.test.ts b/test/repo-owners.test.ts index 3c56ea5d..1f463bcc 100644 --- a/test/repo-owners.test.ts +++ b/test/repo-owners.test.ts @@ -11,16 +11,15 @@ import { RepoError, trackRepo, trackRepoChecked } from "../src/repos.ts"; import { G } from "./guarded.ts"; import { SCRATCH } from "./scratch.ts"; import { connectDb } from "../src/db/open.ts"; -import { sqliteOnly } from "./test-db.ts"; -test("a tracked repo of another owner is written to under its own owner; storytold repos are unchanged", { skip: sqliteOnly("trackedOwners on db.sync") }, async () => { +test("a tracked repo of another owner is written to under its own owner; storytold repos are unchanged", async () => { resetOwners(); const db = await connectDb(join(mkdtempSync(join(SCRATCH, "owners-")), "o.db")); assert.ok(await trackRepo(db, "t", "example-org/autocraft-sandbox")); await trackRepo(db, "t", "designcraft"); assert.equal(ownerOf("autocraft-sandbox"), "example-org"); assert.equal(ownerOf("designcraft"), "storytold"); - assert.deepEqual(trackedOwners(db.sync!), ["example-org", "storytold"]); + assert.deepEqual(await trackedOwners(db), ["example-org", "storytold"]); await assert.rejects(async () => await trackRepo(db, "t", "other/designcraft"), RepoError); await assert.rejects(async () => await trackRepo(db, "t", "bad owner/x"), RepoError); diff --git a/test/sync-health.test.ts b/test/sync-health.test.ts index cb2af042..c63b898e 100644 --- a/test/sync-health.test.ts +++ b/test/sync-health.test.ts @@ -6,23 +6,28 @@ import { join } from "node:path"; import { test } from "node:test"; import { computeChecks, serveChecks } from "../src/health-checks.ts"; import { GithubError, reconcileNext, runSync } from "../src/mirror.ts"; -import { loadOwners } from "../src/owners.ts"; +import { reloadOwners } from "../src/owners.ts"; import { SCRATCH } from "./scratch.ts"; import { connectDb } from "../src/db/open.ts"; -import { sqliteOnly } from "./test-db.ts"; +import { excluded } from "../src/db/kx.ts"; async function scratchDb() { const db = await connectDb(join(mkdtempSync(join(SCRATCH, "synchealth-")), "m.db")); - await db.script("DELETE FROM tracked_repos"); - await db.script("INSERT INTO tracked_repos (name, added_by, added_at) VALUES ('a','t','x'),('b','t','x')"); + await db.run(db.k.deleteFrom("tracked_repos")); + await db.run(db.k.insertInto("tracked_repos").values([{ name: "a", added_by: "t", added_at: "x" }, { name: "b", added_by: "t", added_at: "x" }])); return db; } -test("a repo that no longer resolves is skipped and recorded; failures and recoveries keep per-repo reads right", { skip: sqliteOnly("loadOwners on db.sync") }, async () => { +test("a repo that no longer resolves is skipped and recorded; failures and recoveries keep per-repo reads right", async () => { await recoveryScenarios(); const db = await scratchDb(); - await db.script("INSERT INTO repos (name, synced_at, high_water, reconciled_at) VALUES ('a','2026-11-02T09:00:00Z','2026-11-02T09:00:00Z','2026-11-01T00:00:00Z'),('b','2026-11-02T09:00:00Z','2026-11-02T09:00:00Z','2026-11-02T00:00:00Z')"); - await db.script("INSERT INTO settings VALUES ('org_high_water','2026-11-02T09:30:00Z'),('repos_refreshed_at','2999-01-01T00:00:00Z'),('search_catchup_at','2999-01-01T00:00:00Z')"); + await db.run(db.k.insertInto("repos").values([ + { name: "a", synced_at: "2026-11-02T09:00:00Z", high_water: "2026-11-02T09:00:00Z", reconciled_at: "2026-11-01T00:00:00Z" }, + { name: "b", synced_at: "2026-11-02T09:00:00Z", high_water: "2026-11-02T09:00:00Z", reconciled_at: "2026-11-02T00:00:00Z" }, + ])); + await db.run(db.k.insertInto("settings").values([ + { key: "org_high_water", value: "2026-11-02T09:30:00Z" }, { key: "repos_refreshed_at", value: "2999-01-01T00:00:00Z" }, { key: "search_catchup_at", value: "2999-01-01T00:00:00Z" }, + ])); const client = { spent: 0, remaining: 4000 as number | null, repoMovedTo: (owner: string, name: string) => `elsewhere/${name}-${owner.length}`, @@ -37,7 +42,7 @@ test("a repo that no longer resolves is skipped and recorded; failures and recov const err = await db.prepare("SELECT repo, kind, moved_to FROM sync_repo_errors").all(); assert.deepEqual(err.map((e) => ({ ...e })), [{ repo: "a", kind: "not-found", moved_to: "elsewhere/a-9" }]); // The failing repo gives up its place at the front of the daily reconcile, so repo b is next. - assert.equal((await db.prepare("SELECT reconciled_at AS t FROM repos WHERE name = 'a'").get() as { t: string }).t, "2026-11-02T10:05:00Z"); + assert.equal((await db.get(db.k.selectFrom("repos").select("reconciled_at as t").where("name", "=", "a")))!.t, "2026-11-02T10:05:00Z"); const check = (await computeChecks(db, Date.parse("2026-11-02T10:06:00Z"))).find((c) => c.id === "sync-repo:a"); assert.equal(check?.state, "warn"); assert.match(check!.text, /storytold\/a no longer resolves on GitHub \(moved to elsewhere\/a-9\)/); @@ -54,8 +59,8 @@ const conn = (nodes: unknown[]) => ({ nodes, pageInfo: { hasNextPage: false, end async function recoveryScenarios(): Promise { // A new repo whose first read fails with a plain error is retried per repo, not marked synced by a search. const db = await scratchDb(); - await db.script("INSERT INTO repos (name, synced_at, high_water, reconciled_at) VALUES ('a','2026-11-02T09:00:00Z','2026-11-02T09:00:00Z','2026-11-02T09:00:00Z')"); - await db.script("INSERT INTO settings VALUES ('org_high_water','2026-11-02T09:30:00Z'),('search_catchup_at','2999-01-01T00:00:00Z')"); + await db.run(db.k.insertInto("repos").values({ name: "a", synced_at: "2026-11-02T09:00:00Z", high_water: "2026-11-02T09:00:00Z", reconciled_at: "2026-11-02T09:00:00Z" })); + await db.run(db.k.insertInto("settings").values([{ key: "org_high_water", value: "2026-11-02T09:30:00Z" }, { key: "search_catchup_at", value: "2999-01-01T00:00:00Z" }])); const client = { spent: 0, remaining: 4000 as number | null, async query(query: string, v: Record) { @@ -70,18 +75,20 @@ async function recoveryScenarios(): Promise { }; const o = { only: [], all: false, full: false, perRepo: false }; assert.equal((await runSync(db, client, o, new Date("2026-11-02T10:05:00Z"))).mode, "per-repo"); - await db.prepare("INSERT INTO settings VALUES ('repos_refreshed_at','2999-01-01T00:00:00Z') ON CONFLICT(key) DO UPDATE SET value = excluded.value").run(); + await db.run(db.k.insertInto("settings").values({ key: "repos_refreshed_at", value: "2999-01-01T00:00:00Z" }).onConflict((oc) => oc.column("key").doUpdateSet(excluded(["value"])))); assert.equal((await runSync(db, client, o, new Date("2026-11-02T10:06:00Z"))).mode, "per-repo"); - assert.equal((await db.prepare("SELECT synced_at AS t FROM repos WHERE name = 'b'").get() as { t: string | null }).t, null); + assert.equal((await db.get(db.k.selectFrom("repos").select("synced_at as t").where("name", "=", "b")))!.t, null); // A repo of another owner that failed for hours reads from its own high water when it recovers. const db2 = await scratchDb(); - await db2.script("DELETE FROM tracked_repos"); - await db2.script("INSERT INTO tracked_repos (name, added_by, added_at) VALUES ('c','t','x')"); - await db2.script("INSERT INTO repos (name, owner, synced_at, high_water, reconciled_at) VALUES ('c','other','2026-11-02T08:00:00Z','2026-11-02T08:00:00Z','2026-11-02T09:00:00Z')"); - await db2.script("INSERT INTO settings VALUES ('org_high_water','2026-11-02T10:00:00Z'),('repos_refreshed_at','2999-01-01T00:00:00Z'),('search_catchup_at','2999-01-01T00:00:00Z')"); - await db2.script("INSERT INTO sync_repo_errors VALUES ('c','transient','x','','2026-11-02T08:30:00Z','2026-11-02T10:00:00Z')"); - loadOwners(db2.sync!); + await db2.run(db2.k.deleteFrom("tracked_repos")); + await db2.run(db2.k.insertInto("tracked_repos").values({ name: "c", added_by: "t", added_at: "x" })); + await db2.run(db2.k.insertInto("repos").values({ name: "c", owner: "other", synced_at: "2026-11-02T08:00:00Z", high_water: "2026-11-02T08:00:00Z", reconciled_at: "2026-11-02T09:00:00Z" })); + await db2.run(db2.k.insertInto("settings").values([ + { key: "org_high_water", value: "2026-11-02T10:00:00Z" }, { key: "repos_refreshed_at", value: "2999-01-01T00:00:00Z" }, { key: "search_catchup_at", value: "2999-01-01T00:00:00Z" }, + ])); + await db2.run(db2.k.insertInto("sync_repo_errors").values({ repo: "c", kind: "transient", message: "x", moved_to: "", since: "2026-11-02T08:30:00Z", at: "2026-11-02T10:00:00Z" })); + await reloadOwners(db2); const c2 = { spent: 0, remaining: 4000 as number | null, async query(query: string, v: Record) { @@ -91,15 +98,15 @@ async function recoveryScenarios(): Promise { }, }; await runSync(db2, c2, o, new Date("2026-11-02T10:05:00Z")); - assert.equal((await db2.prepare("SELECT COUNT(*) AS n FROM items WHERE repo = 'c'").get() as { n: number }).n, 1); - assert.equal((await db2.prepare("SELECT COUNT(*) AS n FROM sync_repo_errors").get() as { n: number }).n, 0); + assert.equal((await db2.get(db2.k.selectFrom("items").select((eb) => eb.fn.countAll().as("n")).where("repo", "=", "c")))!.n, 1); + assert.equal((await db2.get(db2.k.selectFrom("sync_repo_errors").select((eb) => eb.fn.countAll().as("n"))))!.n, 0); } test("GET /healthz/checks answers 503 with a stale worker and shows no repo names", async () => { const db = await scratchDb(); const now = Date.parse("2026-11-05T12:00:00Z"); const at = (msAgo: number) => new Date(now - msAgo).toISOString(); - await db.prepare("INSERT INTO settings (key, value) VALUES ('runner_heartbeat', ?)").run(at(5_000)); + await db.run(db.k.insertInto("settings").values({ key: "runner_heartbeat", value: at(5_000) })); await db.prepare("INSERT INTO sync_runs (started_at, ended_at, mode, items) VALUES (?, ?, 'search', 0)").run(at(70_000), at(60_000)); await db.prepare("INSERT INTO build_envs (id, label, kind, enabled, slots, key_hash, last_seen_at, created_at) VALUES ('sandbox','Sandbox','local-sandbox',1,2,'h',?,?)").run(at(6 * 60_000), at(86_400_000)); await db.prepare("INSERT INTO sync_repo_errors (repo, kind, message, since, at) VALUES ('a','not-found','x',?,?)").run(at(1000), at(1000));