fix(workers): skip background jobs when required tables are missing
This commit is contained in:
24
Backend/utils/db-schema.ts
Normal file
24
Backend/utils/db-schema.ts
Normal 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);
|
||||
};
|
||||
Reference in New Issue
Block a user