Phase7c: Fix Cronjob
All checks were successful
Build and Push / build (push) Successful in 1m44s

This commit is contained in:
2026-05-26 23:43:04 +02:00
parent e69b68b73c
commit 9939f75c03

View File

@@ -3342,15 +3342,28 @@ export async function listAutoIssueOrgIds(): Promise<string[]> {
*/ */
export async function listInvoicesPendingReminders(): Promise<Invoice[]> { export async function listInvoicesPendingReminders(): Promise<Invoice[]> {
await ensureSchema(); await ensureSchema();
// Bug fix: the prior version did `FROM invoices i JOIN org_billing_config c ON c.zitadel_org_id = i.zitadel_org_id`,
// but INVOICE_LIST_COLUMNS selects unqualified column names —
// `zitadel_org_id` appears in both tables and Postgres rejects
// it as ambiguous. Rewriting as a subquery filter keeps every
// referenced column on the single `invoices` row source, so the
// unqualified list stays valid (matching every other caller of
// INVOICE_LIST_COLUMNS in this file).
//
// Semantics are unchanged: only include invoices belonging to
// orgs that have opted into auto-reminders. Orgs with no
// org_billing_config row at all are excluded (same as before —
// the inner join didn't match for them either).
const result = await getPool().query( const result = await getPool().query(
`SELECT ${INVOICE_LIST_COLUMNS} `SELECT ${INVOICE_LIST_COLUMNS}
FROM invoices i FROM invoices
JOIN org_billing_config c WHERE status IN ('open','overdue')
ON c.zitadel_org_id = i.zitadel_org_id AND due_at < now() - INTERVAL '7 days'
AND c.auto_reminders_enabled = TRUE AND zitadel_org_id IN (
WHERE i.status IN ('open','overdue') SELECT zitadel_org_id FROM org_billing_config
AND i.due_at < now() - INTERVAL '7 days' WHERE auto_reminders_enabled = TRUE
ORDER BY i.due_at ASC` )
ORDER BY due_at ASC`
); );
return result.rows.map(rowToInvoice); return result.rows.map(rowToInvoice);
} }