fix(workers): skip background jobs when required tables are missing

This commit is contained in:
2026-01-28 17:05:00 +00:00
parent 83d7e1a465
commit 4043d69452
4 changed files with 82 additions and 15 deletions

View File

@@ -0,0 +1,24 @@
import { pool } from '../db/client';
const PUBLIC_SCHEMA = 'public';
export const tableExists = async (tableName: string): Promise<boolean> => {
const result = await pool.query<{ exists: boolean }>(
`
select exists (
select 1
from information_schema.tables
where table_schema = $1
and table_name = $2
) as "exists"
`,
[PUBLIC_SCHEMA, tableName],
);
return result.rows[0]?.exists === true;
};
export const hasRequiredTables = async (tableNames: string[]): Promise<boolean> => {
const checks = await Promise.all(tableNames.map((tableName) => tableExists(tableName)));
return checks.every(Boolean);
};