fix(lab-content-engine): phase 5 test seed — фильтр несуществующих колонок

seedRow падал 'table topics has no column named slug': в схеме topics нет slug
(дрейф между ветками). seedRow теперь оставляет ТОЛЬКО ключи-реальные колонки
(PRAGMA table_info) и доливает required NOT NULL. lab-links 18/18, оба файла 29/29.
+ PLAN: строка Фазы 5 = done.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Maxim Dolgolyov
2026-05-30 16:53:09 +03:00
parent 0500a4a37c
commit 8edab4638b
+9 -4
View File
@@ -21,11 +21,16 @@ after(() => cleanup());
*/
function seedRow(table, provided) {
const cols = db.prepare(`PRAGMA table_info(${table})`).all();
const row = { ...provided };
const colNames = new Set(cols.map(c => c.name));
// Keep ONLY keys that are real columns (drops fields absent in this schema —
// robust to drift, e.g. topics may lack slug/subject_id on some branches).
const row = {};
for (const k of Object.keys(provided)) if (colNames.has(k)) row[k] = provided[k];
// Fill any required (NOT NULL, no default) column the caller didn't provide.
for (const c of cols) {
if (c.pk) continue; // skip primary key (autoincrement)
if (c.name in row) continue; // caller-provided
if (c.notnull && c.dflt_value === null) { // required, no default → fill placeholder
if (c.pk) continue;
if (c.name in row) continue;
if (c.notnull && c.dflt_value === null) {
row[c.name] = /INT|REAL|NUM/i.test(c.type) ? 0 : '';
}
}