Skip to content

Commit fadd56f

Browse files
committed
Fix Postgate compatibility issues in worker queries
- Add asUuid() helper to cast text columns to UUID in joins - Fix findWorkerAssetsBinding join syntax (was generating double =) - Add enumCast for enum_binding_type comparison with Postgate - Restore accessKeyId/secretAccessKey in StorageConfigRow (needed for S3 credentials) Fixes: Database error on worker upload via Postgate HTTP proxy
1 parent 07794f3 commit fadd56f

4 files changed

Lines changed: 26 additions & 5 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openworkers-api",
3-
"version": "1.5.3",
3+
"version": "1.5.4",
44
"license": "MIT",
55
"module": "src/index.ts",
66
"type": "module",

src/services/db/kysely-helpers.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,13 @@ export const byteaToText = (column: string): RawBuilder<string> => {
126126
export const enumToText = <T = string>(column: string): RawBuilder<T> => {
127127
return sql<T>`${sql.ref(column)}::text`;
128128
};
129+
130+
/**
131+
* Cast text column to UUID
132+
* @example
133+
* .innerJoin('table as t', (join) => join.on('t.id', '=', asUuid('ev.value')))
134+
* // Generates: t.id = ev.value::uuid
135+
*/
136+
export const asUuid = (column: string): RawBuilder<string> => {
137+
return sql<string>`${sql.ref(column)}::uuid`;
138+
};

src/services/db/storage.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,25 @@ export interface StorageConfigRow {
88
desc: string | null;
99
bucket: string;
1010
prefix: string | null;
11+
accessKeyId: string;
12+
secretAccessKey: string;
1113
endpoint: string | null;
1214
region: string | null;
1315
publicUrl: string | null;
1416
createdAt: Date;
1517
updatedAt: Date;
1618
}
1719

18-
const storageConfigSelect = [...resourceSelect, 'bucket', 'prefix', 'endpoint', 'region', 'publicUrl'] as const;
20+
const storageConfigSelect = [
21+
...resourceSelect,
22+
'bucket',
23+
'prefix',
24+
'endpoint',
25+
'region',
26+
'publicUrl',
27+
'accessKeyId',
28+
'secretAccessKey'
29+
] as const;
1930

2031
export async function findAllStorageConfigs(userId: string): Promise<StorageConfigRow[]> {
2132
return kysely

src/services/db/workers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { kysely } from './kysely-client';
2-
import { uuid, uuidOrNull, enumCast, base64Decode, byteaToText, enumToText } from './kysely-helpers';
2+
import { uuid, uuidOrNull, enumCast, base64Decode, byteaToText, enumToText, asUuid } from './kysely-helpers';
33
import type { IWorker, IWorkerLanguage } from '../../types';
44
import { sha256Hex } from '../../utils/crypto';
55
import { stringToBase64 } from '../../utils/base64';
@@ -275,7 +275,7 @@ export async function findWorkerAssetsBinding(userId: string, workerId: string):
275275
const binding = await kysely
276276
.selectFrom('workers as w')
277277
.innerJoin('environmentValues as ev', 'ev.environmentId', 'w.environmentId')
278-
.innerJoin('storageConfigs as sc', (join) => join.on('sc.id', '=', sql`sc.id = ev.value::uuid`))
278+
.innerJoin('storageConfigs as sc', (join) => join.on('sc.id', '=', asUuid('ev.value')))
279279
.select([
280280
'sc.id as storageConfigId',
281281
'sc.bucket',
@@ -287,7 +287,7 @@ export async function findWorkerAssetsBinding(userId: string, workerId: string):
287287
])
288288
.where('w.id', '=', uuid(workerId))
289289
.where('w.userId', '=', uuid(userId))
290-
.where('ev.type', '=', 'assets')
290+
.where('ev.type', '=', enumCast('assets', 'enum_binding_type'))
291291
.executeTakeFirst();
292292

293293
return binding ?? null;

0 commit comments

Comments
 (0)