Peter Boling
Peter Boling
DTDrizzle Team
Created by nr7751 on 2/26/2024 in #help
Can someone direct me to a UUID implementation as PK with Drizzle ORM?
@nr7751 I described my solution over on the Lucia discord: https://discord.com/channels/1004048134218981416/1219330483796574270/1219342383918092318
25 replies
DTDrizzle Team
Created by nr7751 on 2/26/2024 in #help
Can someone direct me to a UUID implementation as PK with Drizzle ORM?
Probably best to start there, the performance difference won't matter until you hit millions of users!
25 replies
DTDrizzle Team
Created by nr7751 on 2/26/2024 in #help
Can someone direct me to a UUID implementation as PK with Drizzle ORM?
No, if you are using text it will just work 🙂
25 replies
DTDrizzle Team
Created by nr7751 on 2/26/2024 in #help
Can someone direct me to a UUID implementation as PK with Drizzle ORM?
I did end up getting everything working, except for the session id. All my other IDs are now uuid, and they are v7 when generated by Javascript clients, and v4 when generated by the database.
25 replies
DTDrizzle Team
Created by nr7751 on 2/26/2024 in #help
Can someone direct me to a UUID implementation as PK with Drizzle ORM?
The issue is that Drizzle + Lucia doesn't allow me to override the type of the session id (they only just added the ability to override the type of the user id).
25 replies
DTDrizzle Team
Created by nr7751 on 2/26/2024 in #help
Can someone direct me to a UUID implementation as PK with Drizzle ORM?
uuidv7 is binary format compatible with the older uuid formats, so I can store a uuidv7 inside a uuid field from uuid-ossp
25 replies
DTDrizzle Team
Created by nr7751 on 2/26/2024 in #help
Can someone direct me to a UUID implementation as PK with Drizzle ORM?
I want to use either ulid or uuidv7
25 replies
DTDrizzle Team
Created by nr7751 on 2/26/2024 in #help
Can someone direct me to a UUID implementation as PK with Drizzle ORM?
uuid is a native binary type with the postgresql extension uuid-ossp, but it only ships with a generator for UUID v1, v3, v4, and v5
25 replies
DTDrizzle Team
Created by nr7751 on 2/26/2024 in #help
Can someone direct me to a UUID implementation as PK with Drizzle ORM?
id: text("id")
id: text("id")
I specifically am attempting to avoid using a text field as that bloats the size of the key immensely. I want it to be binary.
25 replies
DTDrizzle Team
Created by Jonas on 2/29/2024 in #help
ClientAuthentication Error using heroku-postgres
Figured it out! I had to set sslmode=require, or ssl: true, everywhere possible, and then it suddenly started working! It appears this is now required by Heroku always. https://devcenter.heroku.com/articles/connecting-heroku-postgres#heroku-postgres-ssl More: https://devcenter.heroku.com/changelog-items/2035
10 replies
DTDrizzle Team
Created by polkovnik on 7/27/2023 in #help
Introspect failing no pg_hba.conf entry for host
6 replies
DTDrizzle Team
Created by polkovnik on 7/27/2023 in #help
Introspect failing no pg_hba.conf entry for host
I had to set sslmode=require, or ssl: true, everywhere possible, and then it suddenly started working! It appears this is now required by Heroku always. https://devcenter.heroku.com/articles/connecting-heroku-postgres#heroku-postgres-ssl
6 replies
DTDrizzle Team
Created by polkovnik on 7/27/2023 in #help
Introspect failing no pg_hba.conf entry for host
Struggling with the same thing, but adding ?sslmode=no-verify hasn't worked yet
6 replies
DTDrizzle Team
Created by Jonas on 2/29/2024 in #help
ClientAuthentication Error using heroku-postgres
I'm struggling with the same thing
10 replies
DTDrizzle Team
Created by nr7751 on 2/26/2024 in #help
Can someone direct me to a UUID implementation as PK with Drizzle ORM?
And this is the migrate script (src/lib/db/db_migrate.server.ts):
import { drizzle } from "drizzle-orm/postgres-js";
import { migrate } from "drizzle-orm/postgres-js/migrator";
import postgres from "postgres";
// We can't use svelte env vars here because migrations run without loading svelte or vite.
import * as dotenv from 'dotenv';
dotenv.config();
const DATABASE_NAME = process.env.DATABASE_NAME ?? 'demo-db';
const DATABASE_URL = process.env.DATABASE_URL ?? `postgres://localhost:5432/${DATABASE_NAME}`;
if (!DATABASE_URL) {
throw new Error('db_migrate: No url for Scripting SQL');
}
// No output on presence of DATABASE_URL because this will run in production deploys

const sql = postgres(DATABASE_URL, { max: 1 })
const db = drizzle(sql);
await migrate(db, { migrationsFolder: "migrations" });
await sql.end();
import { drizzle } from "drizzle-orm/postgres-js";
import { migrate } from "drizzle-orm/postgres-js/migrator";
import postgres from "postgres";
// We can't use svelte env vars here because migrations run without loading svelte or vite.
import * as dotenv from 'dotenv';
dotenv.config();
const DATABASE_NAME = process.env.DATABASE_NAME ?? 'demo-db';
const DATABASE_URL = process.env.DATABASE_URL ?? `postgres://localhost:5432/${DATABASE_NAME}`;
if (!DATABASE_URL) {
throw new Error('db_migrate: No url for Scripting SQL');
}
// No output on presence of DATABASE_URL because this will run in production deploys

const sql = postgres(DATABASE_URL, { max: 1 })
const db = drizzle(sql);
await migrate(db, { migrationsFolder: "migrations" });
await sql.end();
25 replies
DTDrizzle Team
Created by nr7751 on 2/26/2024 in #help
Can someone direct me to a UUID implementation as PK with Drizzle ORM?
❯ tsx src/lib/db/db_migrate.server.ts

> [email protected] db:migrate /Users/pboling/src/fisecal/monolith
> tsx src/lib/db/db_migrate.server.ts

node:internal/process/esm_loader:34
internalBinding('errors').triggerUncaughtException(
^

PostgresError: column "id" cannot be cast automatically to type uuid
at ErrorResponse (file:///Users/pboling/src/fisecal/monolith/node_modules/.pnpm/[email protected]/node_modules/postgres/src/connection.js:790:26)
at handle (file:///Users/pboling/src/fisecal/monolith/node_modules/.pnpm/[email protected]/node_modules/postgres/src/connection.js:476:6)
at Socket.data (file:///Users/pboling/src/fisecal/monolith/node_modules/.pnpm/[email protected]/node_modules/postgres/src/connection.js:315:9)
at Socket.emit (node:events:518:28)
at Socket.emit (node:domain:488:12)
at addChunk (node:internal/streams/readable:559:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
at Readable.push (node:internal/streams/readable:390:5)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
severity_local: 'ERROR',
severity: 'ERROR',
code: '42804',
hint: 'You might need to specify "USING id::uuid".',
file: 'tablecmds.c',
line: '12318',
routine: 'ATPrepAlterColumnType'
}
❯ tsx src/lib/db/db_migrate.server.ts

> [email protected] db:migrate /Users/pboling/src/fisecal/monolith
> tsx src/lib/db/db_migrate.server.ts

node:internal/process/esm_loader:34
internalBinding('errors').triggerUncaughtException(
^

PostgresError: column "id" cannot be cast automatically to type uuid
at ErrorResponse (file:///Users/pboling/src/fisecal/monolith/node_modules/.pnpm/[email protected]/node_modules/postgres/src/connection.js:790:26)
at handle (file:///Users/pboling/src/fisecal/monolith/node_modules/.pnpm/[email protected]/node_modules/postgres/src/connection.js:476:6)
at Socket.data (file:///Users/pboling/src/fisecal/monolith/node_modules/.pnpm/[email protected]/node_modules/postgres/src/connection.js:315:9)
at Socket.emit (node:events:518:28)
at Socket.emit (node:domain:488:12)
at addChunk (node:internal/streams/readable:559:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
at Readable.push (node:internal/streams/readable:390:5)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
severity_local: 'ERROR',
severity: 'ERROR',
code: '42804',
hint: 'You might need to specify "USING id::uuid".',
file: 'tablecmds.c',
line: '12318',
routine: 'ATPrepAlterColumnType'
}
25 replies
DTDrizzle Team
Created by nr7751 on 2/26/2024 in #help
Can someone direct me to a UUID implementation as PK with Drizzle ORM?
I am having the same issue. I am able to run generate:pg and push:pg without issue using code like you gave @Blixkreeg . However, when I use the example code from the running migrations docs I get an error, same as @nr7751 did.
25 replies
DTDrizzle Team
Created by Peter Boling on 2/23/2024 in #help
How to Squash Migrations?
✨ Solution! ✨ My scripts:
"scripts": {
"db:setup": "tsx src/lib/db/setup.server.ts",
"db:studio": "drizzle-kit studio --config drizzle.config.ts",
"db:generate": "drizzle-kit generate:pg --config drizzle.config.ts",
"db:migrate": "drizzle-kit push:pg --config drizzle.config.ts",
"db:squash": "rm -rf migrations/* && pnpm db:setup && pnpm db:generate && pnpm db:migrate",
"setup": "pnpm db:setup && pnpm db:migrate",
"scripts": {
"db:setup": "tsx src/lib/db/setup.server.ts",
"db:studio": "drizzle-kit studio --config drizzle.config.ts",
"db:generate": "drizzle-kit generate:pg --config drizzle.config.ts",
"db:migrate": "drizzle-kit push:pg --config drizzle.config.ts",
"db:squash": "rm -rf migrations/* && pnpm db:setup && pnpm db:generate && pnpm db:migrate",
"setup": "pnpm db:setup && pnpm db:migrate",
My src/lib/db/setup.server.ts is in this gist: https://gist.github.com/pboling/f831235a1f3c5627f0341c4bbcf37ea9#file-setup-server-ts
3 replies
DTDrizzle Team
Created by Peter Boling on 2/23/2024 in #help
How to Squash Migrations?
Indeed, searching this discord for "squash" has zero hits 🥹
3 replies