playsonmac
playsonmac
Explore posts from servers
CDCloudflare Developers
Created by playsonmac on 2/2/2025 in #workers-help
Websocket subprotocol results in Error: The script will never generate a response.
Websockets - sending subprotocols (auth token smuggling) results in Error: The script will never generate a response. Client:
const ws = new WebSocket(wsUrl, "potato");
const ws = new WebSocket(wsUrl, "potato");
Using hono for the worker:
app.get(
"/ws",
upgradeWebSocket((c) => {
const rawProtocols = c.req.header("sec-websocket-protocol");
console.log(rawProtocols);

return {
onMessage: (event) => {
console.log(event.data);
},
};
})
);
app.get(
"/ws",
upgradeWebSocket((c) => {
const rawProtocols = c.req.header("sec-websocket-protocol");
console.log(rawProtocols);

return {
onMessage: (event) => {
console.log(event.data);
},
};
})
);
Fails right away at the upgrade with Error: The script will never generate a response. on the server. This only happens if I send a subprotocol such as "potato" which automatically gets converted to the sec-websocket-protocol header as it should. Curiously I can see the header in the console log. Also tried with hc, same issue.
1 replies
HHono
Created by playsonmac on 2/2/2025 in #help
Websocket subprotocol results in Error: The script will never generate a response
Websockets - sending subprotocols (auth token smuggling) results in Error: The script will never generate a response. Client:
const ws = new WebSocket(wsUrl, "potato");
const ws = new WebSocket(wsUrl, "potato");
Hono:
app.get(
"/ws",
upgradeWebSocket((c) => {
const rawProtocols = c.req.header("sec-websocket-protocol");
console.log(rawProtocols);

return {
onMessage: (event) => {
console.log(event.data);
},
};
})
);
app.get(
"/ws",
upgradeWebSocket((c) => {
const rawProtocols = c.req.header("sec-websocket-protocol");
console.log(rawProtocols);

return {
onMessage: (event) => {
console.log(event.data);
},
};
})
);
- Fails right away at the upgrade with Error: The script will never generate a response. on the server. - This only happens if I send a subprotocol such as "potato" which automatically gets converted to the sec-websocket-protocol header as it should. Curiously I can see the header in the console log. - Also tried with hc, same issue.
23 replies
DTDrizzle Team
Created by playsonmac on 1/13/2025 in #help
drizzle-seed: how to avoid duplicate key value violates unique constraint for composite keys?
I have a usersWorkspaces table which references users and workspaces. When I run the seed script (I haven't defined any behavior for userWorkspaces), I'm getting the following error:
PostgresError: duplicate key value violates unique constraint "user_workspaces_user_id_workspace_id_pk"
severity_local: 'ERROR',
severity: 'ERROR',
code: '23505',
detail: 'Key (user_id, workspace_id)=(d082bd94-0b99-4e48-528d-3d4217c3e50f, 1c40f298-7c31-4fde-0efb-7ce7cbdbd2af) already exists.',
schema_name: 'public',
table_name: 'user_workspaces',
constraint_name: 'user_workspaces_user_id_workspace_id_pk',
file: 'nbtinsert.c',
line: '664',
routine: '_bt_check_unique'
}
PostgresError: duplicate key value violates unique constraint "user_workspaces_user_id_workspace_id_pk"
severity_local: 'ERROR',
severity: 'ERROR',
code: '23505',
detail: 'Key (user_id, workspace_id)=(d082bd94-0b99-4e48-528d-3d4217c3e50f, 1c40f298-7c31-4fde-0efb-7ce7cbdbd2af) already exists.',
schema_name: 'public',
table_name: 'user_workspaces',
constraint_name: 'user_workspaces_user_id_workspace_id_pk',
file: 'nbtinsert.c',
line: '664',
routine: '_bt_check_unique'
}
It seems the seed script is trying to create duplicate entries violating the composite key. I saw that currently drizzle-seed doesn't support the third parameter in Drizzle tables, which I suppose includes the composite primary key. What's a good way to go around this?
1 replies
DTDrizzle Team
Created by playsonmac on 1/13/2025 in #help
[Solved] How to see a supabase with references to authUsers.id?
I have a supabase postgres and I'm trying to seed a table (permissions) with a foreign key to the drizzle-orm/supabase authUsers table. Here's what I'm getting when I try to seed permissions:
Error: Column 'userId' has not null contraint,
and you didn't specify a table for foreign key on column 'userId' in 'permissions' table.
Error: Column 'userId' has not null contraint,
and you didn't specify a table for foreign key on column 'userId' in 'permissions' table.
2 replies
DTDrizzle Team
Created by playsonmac on 1/12/2025 in #help
[Solved] drizzle-seed autocomplete not working if there are enums or zod objects
Not sure which tag to use for drizzle-seed . I'm trying to seed my database and I was surprised that I wouldn't get table autocomplete inside the seed function when the schema is in different files. Whenever I import * from "./single-file" everything seems to work. Curiously when I deconstruct the import for a specific table, I lose the autocompelte. The tsconfig is in the comment below. Case 1 (works) - import * as schema from "./schema/contexts"
import { seed } from "drizzle-seed";
import * as schema from "./schema/contexts";
import { linkDatabase } from ".";

const main = async () => {
const { db } = linkDatabase();

await seed(db, schema).refine((f) => ({
// contexts gets suggested
}));
};

main();
import { seed } from "drizzle-seed";
import * as schema from "./schema/contexts";
import { linkDatabase } from ".";

const main = async () => {
const { db } = linkDatabase();

await seed(db, schema).refine((f) => ({
// contexts gets suggested
}));
};

main();
Case 2 (doesn't work when the schema is distributed in different files) - import * as schema from "./schema/"
import { seed } from "drizzle-seed";
import * as schema from "./schema/";
import { linkDatabase } from ".";


const main = async () => {
const { db } = linkDatabase();

await seed(db, schema).refine((f) => ({
// contexts doesn't get autocompleted
}));
};

main();
import { seed } from "drizzle-seed";
import * as schema from "./schema/";
import { linkDatabase } from ".";


const main = async () => {
const { db } = linkDatabase();

await seed(db, schema).refine((f) => ({
// contexts doesn't get autocompleted
}));
};

main();
Case 3 (doesn't work when the import is deconstructed - import { contexts } from "./schema/contexts"
import { seed } from "drizzle-seed";
import { contexts } from "./schema/contexts";
import { linkDatabase } from ".";

const main = async () => {
const { db } = linkDatabase();

await seed(db, contexts).refine((f) => ({ // Note that contexts gets passed here
// contexts doesn't get autocompleted
}));
};

main();
import { seed } from "drizzle-seed";
import { contexts } from "./schema/contexts";
import { linkDatabase } from ".";

const main = async () => {
const { db } = linkDatabase();

await seed(db, contexts).refine((f) => ({ // Note that contexts gets passed here
// contexts doesn't get autocompleted
}));
};

main();
Would appreciate any ideas, thanks!
5 replies
DTDrizzle Team
Created by playsonmac on 1/10/2025 in #help
drizzle-zod 0.6.1 has errors on each createXyzSchema
Hey everyone, Does anyone know how to handle this error:
The inferred type of 'selectWorkspacesSchema' cannot be named without a reference to '../node_modules/drizzle-zod/schema.types.internal.mjs'. This is likely not portable. A type annotation is necessary. ts(2742)
The inferred type of 'selectWorkspacesSchema' cannot be named without a reference to '../node_modules/drizzle-zod/schema.types.internal.mjs'. This is likely not portable. A type annotation is necessary. ts(2742)
I'm getting it on createSelectSchema(table), createUpdateSchema(table) and createInsertSchema(table) Thanks!
3 replies
DTDrizzle Team
Created by playsonmac on 11/7/2024 in #help
Supabase SSL - ENAMETOOLONG when adding sslrootcert to dbCredentials url
I'm trying to connect to my supabase with ssl-enabled using drizzle-kit but I keep on getting ENAMETOOLONG. I'm encoding the certificate into the connection url, but it seems like I'm reaching the limits of path length. My code is literally the same as was posted by budivoogt: https://github.com/orgs/supabase/discussions/18710#discussioncomment-10614735 "I got this working with Drizzle as follows:"
drizzle.config.ts:

import { defineConfig } from 'drizzle-kit'
import * as fs from 'fs'

const caString = fs.readFileSync('./.supabase/certificates/prod-ca-2021.crt').toString()
// URL encode the certificate
const caStringEncoded = encodeURIComponent(caString)

// Construct the database URL with SSL parameters
const dbUrl = new URL(process.env.DEV_DATABASE_URL as string)
dbUrl.searchParams.append('sslmode', 'require')
dbUrl.searchParams.append('sslrootcert', caStringEncoded)

export default defineConfig({
schema: './src/lib/database/schema.ts',
out: './.drizzle/migrations',
dialect: 'postgresql',
dbCredentials: {
url: dbUrl.toString()
}
})
drizzle.config.ts:

import { defineConfig } from 'drizzle-kit'
import * as fs from 'fs'

const caString = fs.readFileSync('./.supabase/certificates/prod-ca-2021.crt').toString()
// URL encode the certificate
const caStringEncoded = encodeURIComponent(caString)

// Construct the database URL with SSL parameters
const dbUrl = new URL(process.env.DEV_DATABASE_URL as string)
dbUrl.searchParams.append('sslmode', 'require')
dbUrl.searchParams.append('sslrootcert', caStringEncoded)

export default defineConfig({
schema: './src/lib/database/schema.ts',
out: './.drizzle/migrations',
dialect: 'postgresql',
dbCredentials: {
url: dbUrl.toString()
}
})
src/lib/database/db.ts:

import { drizzle } from 'drizzle-orm/postgres-js'
import postgres from 'postgres'
import * as fs from 'fs'

const client = postgres(process.env.DEV_DATABASE_URL as string, {
ssl: {
rejectUnauthorized: true,
// Apply SSL certificate
ca: fs.readFileSync('./.supabase/certificates/prod-ca-2021.crt').toString()
}
})
export const db = drizzle(client)
src/lib/database/db.ts:

import { drizzle } from 'drizzle-orm/postgres-js'
import postgres from 'postgres'
import * as fs from 'fs'

const client = postgres(process.env.DEV_DATABASE_URL as string, {
ssl: {
rejectUnauthorized: true,
// Apply SSL certificate
ca: fs.readFileSync('./.supabase/certificates/prod-ca-2021.crt').toString()
}
})
export const db = drizzle(client)
Ideally, I'd like to be able to have the certificate as an env (yeah, tired that, still the same length issue) so that a cloudflare worker which doesn't have acccess to the fs can connect. Any ideas on how to go around this?
1 replies
CDCloudflare Developers
Created by playsonmac on 11/1/2024 in #pages-help
Nextjs multi-zone deployment?
Do pages support nextjs' multi-zone routing? If so, is there an article or a repo showcasing how one can host both an app (and a blog for example) on the same domain using cf pages and two different instances of nextjs?
1 replies