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:
@@ -21,11 +21,16 @@ after(() => cleanup());
|
|||||||
*/
|
*/
|
||||||
function seedRow(table, provided) {
|
function seedRow(table, provided) {
|
||||||
const cols = db.prepare(`PRAGMA table_info(${table})`).all();
|
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) {
|
for (const c of cols) {
|
||||||
if (c.pk) continue; // skip primary key (autoincrement)
|
if (c.pk) continue;
|
||||||
if (c.name in row) continue; // caller-provided
|
if (c.name in row) continue;
|
||||||
if (c.notnull && c.dflt_value === null) { // required, no default → fill placeholder
|
if (c.notnull && c.dflt_value === null) {
|
||||||
row[c.name] = /INT|REAL|NUM/i.test(c.type) ? 0 : '';
|
row[c.name] = /INT|REAL|NUM/i.test(c.type) ? 0 : '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user