const FIRST_H1_RE = /^#\s+(.+?)\s*$/m;
export function backfillPlanTitles(db) {
    const rows = db
        .prepare(`SELECT id, content FROM plan WHERE title IS NULL`)
        .all();
    if (rows.length === 0)
        return 0;
    const update = db.prepare(`UPDATE plan SET title = ? WHERE id = ?`);
    let updated = 0;
    for (const row of rows) {
        const m = row.content.match(FIRST_H1_RE);
        if (!m)
            continue;
        const title = m[1].trim();
        if (!title)
            continue;
        update.run(title, row.id);
        updated++;
    }
    return updated;
}
//# sourceMappingURL=backfill-plan-titles.js.map