{"record":{"id":"33960ff8065af5b1","repo":"different-ai/openwork","slug":"unable-to-backfill-repair-table-organization-id","errorCode":null,"errorMessage":"Unable to backfill ${repair.table}.organization_id; orphan ids: ${orphanIds.join(\", \")}","messagePattern":"Unable to backfill (.+?)\\.organization_id; orphan ids: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ee/packages/den-db/src/schema-repairs.ts","lineNumber":137,"sourceCode":"    `UPDATE ${table} child_table\n     JOIN ${parentTable} parent_table ON child_table.${foreignKey} = parent_table.\\`id\\`\n     SET child_table.\\`organization_id\\` = parent_table.\\`organization_id\\`\n     WHERE child_table.\\`organization_id\\` IS NULL`,\n  )\n  console.log(`[den-db] ${repair.table}.organization_id backfilled from ${repair.parentTable}`)\n\n  const nullRows = await executor.query(`SELECT COUNT(*) AS null_count FROM ${table} WHERE \\`organization_id\\` IS NULL`)\n  if (numericValue(nullRows, \"null_count\") > 0) {\n    const orphanRows = await executor.query(\n      `SELECT child_table.\\`id\\` AS id FROM ${table} child_table\n       LEFT JOIN ${parentTable} parent_table ON child_table.${foreignKey} = parent_table.\\`id\\`\n       WHERE child_table.\\`organization_id\\` IS NULL\n       LIMIT 20`,\n    )\n    const orphanIds = orphanRows\n      .map((row) => row.id)\n      .filter((id): id is string => typeof id === \"string\")\n    throw new Error(\n      `Unable to backfill ${repair.table}.organization_id; orphan ids: ${orphanIds.join(\", \")}`,\n    )\n  }\n\n  await runDdl(executor, `ALTER TABLE ${table} MODIFY \\`organization_id\\` varchar(64) NOT NULL`)\n  console.log(`[den-db] ${repair.table}.organization_id made NOT NULL`)\n}\n\nasync function repairOrganizationColumn(executor: Executor, repair: OrganizationRepair) {\n  const table = quoteIdentifier(repair.table)\n\n  const countRows = await executor.query(`SELECT COUNT(*) AS row_count FROM ${table}`)\n  if (numericValue(countRows, \"row_count\") === 0) {\n    await runDdl(executor, `ALTER TABLE ${table} ADD COLUMN \\`organization_id\\` varchar(64) NOT NULL AFTER \\`id\\``)\n    console.log(`[den-db] ${repair.table}.organization_id column added`)\n    return\n  }\n","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/packages/den-db/src/schema-repairs.ts#L119-L155","documentation":"Error \"Unable to backfill ${repair.table}.organization_id; orphan ids: ${orphanIds.join(\", \")}\" thrown in different-ai/openwork.","triggerScenarios":"Thrown at ee/packages/den-db/src/schema-repairs.ts:137 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}