( client: ReturnType<typeof getDbExec>, pg: boolean, )
| 85 | } |
| 86 | |
| 87 | async function ensureToolDataItemId( |
| 88 | client: ReturnType<typeof getDbExec>, |
| 89 | pg: boolean, |
| 90 | ): Promise<void> { |
| 91 | if (pg) { |
| 92 | await client.execute( |
| 93 | `ALTER TABLE tool_data ADD COLUMN IF NOT EXISTS item_id TEXT`, |
| 94 | ); |
| 95 | return; |
| 96 | } |
| 97 | |
| 98 | // Keep this additive: legacy rows with item_id=id are still read correctly |
| 99 | // through COALESCE(item_id, id), so SQLite never needs a table rebuild here. |
| 100 | try { |
| 101 | await client.execute(`ALTER TABLE tool_data ADD COLUMN item_id TEXT`); |
| 102 | } catch (err: any) { |
| 103 | if ( |
| 104 | !String(err?.message ?? err) |
| 105 | .toLowerCase() |
| 106 | .includes("duplicate") |
| 107 | ) { |
| 108 | throw err; |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | async function ensureToolDataScope( |
| 114 | client: ReturnType<typeof getDbExec>, |
no test coverage detected