Skip to content

Commit 6d9ce66

Browse files
committed
comments
1 parent ba7a3f3 commit 6d9ce66

File tree

6 files changed

+334
-8
lines changed

6 files changed

+334
-8
lines changed

app/lib/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export const videos = pgTable(
8989
.notNull()
9090
.defaultNow(),
9191
views: bigint("views", { mode: "number" }).notNull().default(0),
92-
fileSizeBytes: real("file_size_bytes").notNull(),
92+
fileSizeBytes: bigint("file_size_bytes", { mode: "number" }).notNull(),
9393
videoLengthSeconds: integer("video_length_seconds"),
9494
isPrivate: boolean("is_private").notNull().default(false),
9595
storyboardJson: jsonb("storyboard_json").$type<VideoStoryboard>(),

app/routes/api/wh/polar.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export const APIRoute = createAPIFileRoute("/api/wh/polar")({
3535
);
3636
}
3737

38+
console.error(error);
39+
3840
return json({ message: "Unknown error" }, { status: 500 });
3941
}
4042
},

app/trigger/handle-polar-event.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,20 @@ export const handlePolarEventTask = schemaTask({
103103
const difference = Math.abs(
104104
currentAmountOfStorage - futureAmountOfStorage
105105
);
106-
let videoSizeDeleted = 0;
106+
let totalSizeRecovered = 0;
107107

108108
const jobs: { payload: { videoId: string } }[] = [];
109109

110-
for (const video of user.videos) {
111-
if (videoSizeDeleted >= difference) {
112-
break;
113-
}
110+
if (difference > 0) {
111+
for (const video of user.videos) {
112+
if (totalSizeRecovered >= difference) {
113+
break;
114+
}
114115

115-
videoSizeDeleted += video.fileSizeBytes;
116+
totalSizeRecovered += video.fileSizeBytes;
116117

117-
jobs.push({ payload: { videoId: video.id } });
118+
jobs.push({ payload: { videoId: video.id } });
119+
}
118120
}
119121

120122
await Promise.all([
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE "videos" ALTER COLUMN "file_size_bytes" SET DATA TYPE bigint;

migrations/meta/0016_snapshot.json

Lines changed: 314 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,314 @@
1+
{
2+
"id": "ad72039c-cfbf-44d3-9607-1496f8f0ec16",
3+
"prevId": "ff4cc84d-a910-4112-a568-8ac39e84782c",
4+
"version": "7",
5+
"dialect": "postgresql",
6+
"tables": {
7+
"public.users": {
8+
"name": "users",
9+
"schema": "",
10+
"columns": {
11+
"id": {
12+
"name": "id",
13+
"type": "text",
14+
"primaryKey": true,
15+
"notNull": true
16+
},
17+
"polar_customer_id": {
18+
"name": "polar_customer_id",
19+
"type": "text",
20+
"primaryKey": false,
21+
"notNull": true
22+
},
23+
"email": {
24+
"name": "email",
25+
"type": "text",
26+
"primaryKey": false,
27+
"notNull": true
28+
},
29+
"created_at": {
30+
"name": "created_at",
31+
"type": "timestamp",
32+
"primaryKey": false,
33+
"notNull": true,
34+
"default": "now()"
35+
},
36+
"account_tier": {
37+
"name": "account_tier",
38+
"type": "text",
39+
"primaryKey": false,
40+
"notNull": true,
41+
"default": "'free'"
42+
},
43+
"total_storage_used": {
44+
"name": "total_storage_used",
45+
"type": "real",
46+
"primaryKey": false,
47+
"notNull": true,
48+
"default": 0
49+
}
50+
},
51+
"indexes": {
52+
"userId_idx": {
53+
"name": "userId_idx",
54+
"columns": [
55+
{
56+
"expression": "id",
57+
"isExpression": false,
58+
"asc": true,
59+
"nulls": "last"
60+
}
61+
],
62+
"isUnique": false,
63+
"concurrently": false,
64+
"method": "btree",
65+
"with": {}
66+
},
67+
"email_idx": {
68+
"name": "email_idx",
69+
"columns": [
70+
{
71+
"expression": "email",
72+
"isExpression": false,
73+
"asc": true,
74+
"nulls": "last"
75+
}
76+
],
77+
"isUnique": false,
78+
"concurrently": false,
79+
"method": "btree",
80+
"with": {}
81+
},
82+
"customerId_idx": {
83+
"name": "customerId_idx",
84+
"columns": [
85+
{
86+
"expression": "polar_customer_id",
87+
"isExpression": false,
88+
"asc": true,
89+
"nulls": "last"
90+
}
91+
],
92+
"isUnique": false,
93+
"concurrently": false,
94+
"method": "btree",
95+
"with": {}
96+
}
97+
},
98+
"foreignKeys": {},
99+
"compositePrimaryKeys": {},
100+
"uniqueConstraints": {}
101+
},
102+
"public.videos": {
103+
"name": "videos",
104+
"schema": "",
105+
"columns": {
106+
"id": {
107+
"name": "id",
108+
"type": "text",
109+
"primaryKey": true,
110+
"notNull": true
111+
},
112+
"author_id": {
113+
"name": "author_id",
114+
"type": "text",
115+
"primaryKey": false,
116+
"notNull": true
117+
},
118+
"title": {
119+
"name": "title",
120+
"type": "text",
121+
"primaryKey": false,
122+
"notNull": true
123+
},
124+
"status": {
125+
"name": "status",
126+
"type": "text",
127+
"primaryKey": false,
128+
"notNull": true,
129+
"default": "'uploading'"
130+
},
131+
"sources": {
132+
"name": "sources",
133+
"type": "jsonb",
134+
"primaryKey": false,
135+
"notNull": true,
136+
"default": "'[]'::jsonb"
137+
},
138+
"small_thumbnail_key": {
139+
"name": "small_thumbnail_key",
140+
"type": "text",
141+
"primaryKey": false,
142+
"notNull": false
143+
},
144+
"large_thumbnail_key": {
145+
"name": "large_thumbnail_key",
146+
"type": "text",
147+
"primaryKey": false,
148+
"notNull": false
149+
},
150+
"created_at": {
151+
"name": "created_at",
152+
"type": "timestamp",
153+
"primaryKey": false,
154+
"notNull": true,
155+
"default": "now()"
156+
},
157+
"updated_at": {
158+
"name": "updated_at",
159+
"type": "timestamp",
160+
"primaryKey": false,
161+
"notNull": true,
162+
"default": "now()"
163+
},
164+
"views": {
165+
"name": "views",
166+
"type": "bigint",
167+
"primaryKey": false,
168+
"notNull": true,
169+
"default": 0
170+
},
171+
"file_size_bytes": {
172+
"name": "file_size_bytes",
173+
"type": "bigint",
174+
"primaryKey": false,
175+
"notNull": true
176+
},
177+
"video_length_seconds": {
178+
"name": "video_length_seconds",
179+
"type": "integer",
180+
"primaryKey": false,
181+
"notNull": false
182+
},
183+
"is_private": {
184+
"name": "is_private",
185+
"type": "boolean",
186+
"primaryKey": false,
187+
"notNull": true,
188+
"default": false
189+
},
190+
"storyboard_json": {
191+
"name": "storyboard_json",
192+
"type": "jsonb",
193+
"primaryKey": false,
194+
"notNull": false
195+
},
196+
"pending_deletion_date": {
197+
"name": "pending_deletion_date",
198+
"type": "timestamp",
199+
"primaryKey": false,
200+
"notNull": false
201+
},
202+
"is_queued_for_deletion": {
203+
"name": "is_queued_for_deletion",
204+
"type": "boolean",
205+
"primaryKey": false,
206+
"notNull": true,
207+
"default": false
208+
}
209+
},
210+
"indexes": {
211+
"authorId_idx": {
212+
"name": "authorId_idx",
213+
"columns": [
214+
{
215+
"expression": "author_id",
216+
"isExpression": false,
217+
"asc": true,
218+
"nulls": "last"
219+
}
220+
],
221+
"isUnique": false,
222+
"concurrently": false,
223+
"method": "btree",
224+
"with": {}
225+
},
226+
"videoId_idx": {
227+
"name": "videoId_idx",
228+
"columns": [
229+
{
230+
"expression": "id",
231+
"isExpression": false,
232+
"asc": true,
233+
"nulls": "last"
234+
}
235+
],
236+
"isUnique": false,
237+
"concurrently": false,
238+
"method": "btree",
239+
"with": {}
240+
},
241+
"createdAt_idx": {
242+
"name": "createdAt_idx",
243+
"columns": [
244+
{
245+
"expression": "created_at",
246+
"isExpression": false,
247+
"asc": true,
248+
"nulls": "last"
249+
}
250+
],
251+
"isUnique": false,
252+
"concurrently": false,
253+
"method": "btree",
254+
"with": {}
255+
},
256+
"status_idx": {
257+
"name": "status_idx",
258+
"columns": [
259+
{
260+
"expression": "status",
261+
"isExpression": false,
262+
"asc": true,
263+
"nulls": "last"
264+
}
265+
],
266+
"isUnique": false,
267+
"concurrently": false,
268+
"method": "btree",
269+
"with": {}
270+
},
271+
"pendingDeletionDate_idx": {
272+
"name": "pendingDeletionDate_idx",
273+
"columns": [
274+
{
275+
"expression": "pending_deletion_date",
276+
"isExpression": false,
277+
"asc": true,
278+
"nulls": "last"
279+
}
280+
],
281+
"isUnique": false,
282+
"concurrently": false,
283+
"method": "btree",
284+
"with": {}
285+
}
286+
},
287+
"foreignKeys": {
288+
"videos_author_id_users_id_fk": {
289+
"name": "videos_author_id_users_id_fk",
290+
"tableFrom": "videos",
291+
"tableTo": "users",
292+
"columnsFrom": [
293+
"author_id"
294+
],
295+
"columnsTo": [
296+
"id"
297+
],
298+
"onDelete": "cascade",
299+
"onUpdate": "no action"
300+
}
301+
},
302+
"compositePrimaryKeys": {},
303+
"uniqueConstraints": {}
304+
}
305+
},
306+
"enums": {},
307+
"schemas": {},
308+
"sequences": {},
309+
"_meta": {
310+
"columns": {},
311+
"schemas": {},
312+
"tables": {}
313+
}
314+
}

migrations/meta/_journal.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@
113113
"when": 1740703976382,
114114
"tag": "0015_tough_wild_pack",
115115
"breakpoints": true
116+
},
117+
{
118+
"idx": 16,
119+
"version": "7",
120+
"when": 1740707737896,
121+
"tag": "0016_aspiring_maria_hill",
122+
"breakpoints": true
116123
}
117124
]
118125
}

0 commit comments

Comments
 (0)