Skip to content

Commit

Permalink
Don't error if there are existing billing historical rows for that te…
Browse files Browse the repository at this point in the history
…nant/month
  • Loading branch information
jshearer committed Aug 29, 2023
1 parent 91b5a95 commit 046c787
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions supabase/migrations/24_billing_historicals.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ declare
tenant_count integer = 0;
begin
for tenant_row in select tenant as tenant_name from tenants loop
tenant_count = tenant_count + 1;
insert into billing_historicals
select
report->>'billed_prefix' as tenant,
date_trunc('month', billed_month) as billed_month,
(report->>'billed_month')::timestamptz as billed_month,
report
from billing_report_202308(tenant_row.tenant_name, date_trunc('month', billed_month)) as report;
from billing_report_202308(tenant_row.tenant_name, billed_month) as report
on conflict do nothing;

-- INSERT statements set FOUND true if at least one row is affected, false if no row is affected.
if found then
tenant_count = tenant_count + 1;
end if;
end loop;
return tenant_count;
end
Expand Down

0 comments on commit 046c787

Please sign in to comment.