fix(tasks): Make pool JOIN defensive when table doesn't exist
Auto-migrate fails early, so task_pools may not exist yet. Check table existence before including pool columns/joins. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -432,7 +432,10 @@ class TaskService {
|
||||
params.push(filter.worker_id);
|
||||
}
|
||||
|
||||
if (filter.pool_id) {
|
||||
// Check if task_pools table exists for pool filtering
|
||||
const poolsExist = await tableExists('task_pools');
|
||||
|
||||
if (filter.pool_id && poolsExist) {
|
||||
conditions.push(`d.pool_id = $${paramIndex++}`);
|
||||
params.push(filter.pool_id);
|
||||
}
|
||||
@@ -441,17 +444,20 @@ class TaskService {
|
||||
const limit = filter.limit ?? 100;
|
||||
const offset = filter.offset ?? 0;
|
||||
|
||||
// Use pool columns only if table exists
|
||||
const poolColumns = poolsExist ? 'd.pool_id as pool_id, tp.display_name as pool_name,' : 'NULL as pool_id, NULL as pool_name,';
|
||||
const poolJoin = poolsExist ? 'LEFT JOIN task_pools tp ON tp.id = d.pool_id' : '';
|
||||
|
||||
const result = await pool.query(
|
||||
`SELECT
|
||||
t.*,
|
||||
d.name as dispensary_name,
|
||||
d.slug as dispensary_slug,
|
||||
d.pool_id as pool_id,
|
||||
tp.display_name as pool_name,
|
||||
${poolColumns}
|
||||
w.friendly_name as worker_name
|
||||
FROM worker_tasks t
|
||||
LEFT JOIN dispensaries d ON d.id = t.dispensary_id
|
||||
LEFT JOIN task_pools tp ON tp.id = d.pool_id
|
||||
${poolJoin}
|
||||
LEFT JOIN worker_registry w ON w.worker_id = t.worker_id
|
||||
${whereClause}
|
||||
ORDER BY t.created_at DESC
|
||||
|
||||
Reference in New Issue
Block a user