Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions sql/reports/sfdc/ba-fees-monthly.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ latest_status AS (
)
SELECT
fp.billing_account AS "billingAccountId",
TO_CHAR(DATE_TRUNC('month', fp.created_at), 'YYYY-MM') AS "month",
TO_CHAR(DATE_TRUNC('month', fp.created_at AT TIME ZONE 'America/New_York'), 'YYYY-MM') AS "month",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The addition of AT TIME ZONE 'America/New_York' to fp.created_at ensures that the date is correctly adjusted to the specified timezone. However, ensure that all relevant parts of the system are aware of this timezone change to avoid inconsistencies, especially if other parts of the system assume UTC or another timezone.

COALESCE(SUM(fp.challenge_fee), 0) AS "totalFees",
COALESCE(SUM(fp.total_amount), 0) AS "totalMemberPayments",
COUNT(fp.payment_id) AS "paymentCount",
MIN(fp.created_at)::date AS "earliestPaymentDate",
MAX(fp.created_at)::date AS "latestPaymentDate",
MIN(fp.created_at AT TIME ZONE 'America/New_York')::date AS "earliestPaymentDate",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The use of AT TIME ZONE 'America/New_York' for MIN(fp.created_at) and MAX(fp.created_at) ensures that the earliest and latest payment dates are correctly adjusted to the specified timezone. Verify that this change aligns with business requirements and that all downstream systems are prepared to handle this timezone adjustment.

MAX(fp.created_at AT TIME ZONE 'America/New_York')::date AS "latestPaymentDate",
ls.payment_status_desc AS "currentPaymentStatus"
FROM filtered_payments fp
LEFT JOIN latest_status ls ON ls.billing_account = fp.billing_account
GROUP BY
fp.billing_account,
DATE_TRUNC('month', fp.created_at),
DATE_TRUNC('month', fp.created_at AT TIME ZONE 'America/New_York'),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The addition of AT TIME ZONE 'America/New_York' to DATE_TRUNC('month', fp.created_at) ensures that the month is calculated based on the specified timezone. Confirm that this change is consistent with how other date calculations are performed across the system to prevent potential discrepancies.

ls.payment_status_desc
ORDER BY fp.billing_account, "month" DESC;
6 changes: 3 additions & 3 deletions sql/reports/sfdc/challenges.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
SELECT
p.id as "paymentId",
c.id as "challengeId",
c.name AS "challengeName",
p.billing_account as "billingAccountId",
c.status as "challengeStatus",
c."endDate" as "completeDate",
p.created_at as "paymentDate",
c."endDate" AT TIME ZONE 'America/New_York' as "completeDate",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ correctness]
The use of AT TIME ZONE 'America/New_York' for c."endDate" assumes that the input timestamp is in UTC. Ensure that the source data is indeed in UTC to avoid incorrect time conversions.

p.created_at AT TIME ZONE 'America/New_York' as "paymentDate",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ correctness]
The use of AT TIME ZONE 'America/New_York' for p.created_at assumes that the input timestamp is in UTC. Ensure that the source data is indeed in UTC to avoid incorrect time conversions.

c."taskIsTask" AS "isTask",
p.challenge_fee as "challengeFee",
p.total_amount as "memberPayments",
Expand Down Expand Up @@ -32,4 +33,3 @@ WHERE
AND ($10::numeric IS NULL OR (p.total_amount + p.challenge_fee) >= $10::numeric)
AND ($11::numeric IS NULL OR (p.total_amount + p.challenge_fee) <= $11::numeric)
ORDER BY c."endDate" DESC, p.created_at DESC

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ performance]
The removal of the LIMIT 1000 clause could lead to performance issues if the result set is large. Consider adding a limit or pagination to manage large datasets efficiently.

LIMIT 1000;
2 changes: 1 addition & 1 deletion sql/reports/sfdc/payments.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SELECT
p.payment_id as "paymentId",
p.created_at as "paymentDate",
p.created_at AT TIME ZONE 'America/New_York' as "paymentDate",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ correctness]
The use of AT TIME ZONE 'America/New_York' changes the timezone of created_at. Ensure that this change aligns with the business requirements, as it will affect how paymentDate is interpreted and displayed. If the application logic or downstream systems expect UTC or another timezone, this could lead to inconsistencies.

p.billing_account as "billingAccountId",
p.payment_status as "paymentStatus",
p.challenge_fee as "challengeFee",
Expand Down
4 changes: 2 additions & 2 deletions sql/reports/sfdc/taas-jobs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ SELECT
j.max_salary AS "maxSalary",
j.hours_per_week AS "hoursPerWeek",
j.currency,
j.created_at AS "createdAt",
j.updated_at AS "updatedAt"
j.created_at AT TIME ZONE 'America/New_York' AS "createdAt",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
Using AT TIME ZONE 'America/New_York' directly in the query can lead to unexpected results during daylight saving time transitions. Consider using a more robust method to handle time zone conversions, such as using a function that accounts for daylight saving time changes.

j.updated_at AT TIME ZONE 'America/New_York' AS "updatedAt"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
Similar to the previous line, ensure that the time zone conversion handles daylight saving time changes correctly to avoid potential issues with timestamp accuracy.

FROM taas.jobs j
WHERE
j.deleted_at IS NULL
Expand Down
4 changes: 2 additions & 2 deletions sql/reports/sfdc/taas-resource-bookings.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ SELECT
rb.customer_rate AS "customerRate",
rb.rate_type AS "rateType",
rb.billing_account_id AS "billingAccountId",
rb.created_at AS "createdAt",
rb.updated_at AS "updatedAt"
rb.created_at AT TIME ZONE 'America/New_York' AS "createdAt",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
Using AT TIME ZONE 'America/New_York' directly in the query can lead to unexpected results during daylight saving time transitions. Consider using a timezone-aware function or storing timestamps in UTC and converting them in the application layer for consistency.

rb.updated_at AT TIME ZONE 'America/New_York' AS "updatedAt"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
Similar to the previous line, applying AT TIME ZONE 'America/New_York' directly in the query may cause issues during daylight saving time changes. It's safer to handle timezone conversions in the application layer or use a timezone-aware function.

FROM taas.resource_bookings rb
LEFT JOIN identity."user" u ON rb.user_id = u.user_id::text
WHERE
Expand Down
2 changes: 1 addition & 1 deletion sql/reports/sfdc/western-union-payments.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ SELECT
reference_id AS "referenceId",
description,
payment_status_desc AS "paymentStatus",
created_at AS "paymentDate"
created_at AT TIME ZONE 'America/New_York' AS "paymentDate"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
Using AT TIME ZONE 'America/New_York' directly in the query can lead to unexpected results during daylight saving time changes. Consider using a timezone-aware function or storing timestamps in UTC and converting them in the application layer to ensure consistent behavior.

FROM payment_data
WHERE
($1::text IS NULL OR payment_status_desc ILIKE $1 OR payment_status::text ILIKE $1)
Expand Down
Loading