Skip to content

Commit 375341f

Browse files
Fix production watched-minute billing sync (#6)
* fix(billing): sync watched minutes reliably * fix(billing): align local storage usage
1 parent 0fb98d3 commit 375341f

6 files changed

Lines changed: 247 additions & 534 deletions

File tree

apps/site/lib/billing.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,6 @@ async function localUsage(context: DashboardAccessContext) {
515515
WHERE asset.organization_id = $1::uuid
516516
AND asset.deleted_at IS NULL
517517
AND asset.duration_ms IS NOT NULL
518-
AND asset.max_resolution_tier IN ('720p', '1080p', '2k', '4k')
519518
`,
520519
[context.organizationId]
521520
);

apps/site/lib/db/schema.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,6 @@ export const billingStorageSpans = rend.table(
302302
.notNull()
303303
.references(() => assets.id, { onDelete: "cascade" }),
304304
duration_ms: bigint("duration_ms", { mode: "number" }).notNull(),
305-
resolution_tier: text("resolution_tier").notNull(),
306305
started_at: timestamp("started_at", { withTimezone: true }).notNull().defaultNow(),
307306
ended_at: timestamp("ended_at", { withTimezone: true }),
308307
created_at: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
@@ -314,7 +313,6 @@ export const billingStorageSpans = rend.table(
314313
.where(sql`${table.ended_at} IS NULL`),
315314
index("billing_storage_spans_org_window_idx").on(
316315
table.organization_id,
317-
table.resolution_tier,
318316
table.started_at,
319317
table.ended_at
320318
),
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
DROP INDEX IF EXISTS rend.billing_storage_spans_org_window_idx;
2+
3+
ALTER TABLE rend.billing_storage_spans
4+
DROP CONSTRAINT IF EXISTS billing_storage_spans_resolution_tier_check,
5+
DROP COLUMN IF EXISTS resolution_tier;
6+
7+
CREATE INDEX IF NOT EXISTS billing_storage_spans_org_window_idx
8+
ON rend.billing_storage_spans(organization_id, started_at, ended_at);

0 commit comments

Comments
 (0)