Skip to content

Conversation

@koistya
Copy link
Member

@koistya koistya commented Dec 5, 2025

Follow-up to #2131 that resolves migration failures for users without the pg_uuidv7 extension.

Database

Switches from uuid_generate_v7() to gen_random_uuid() for universal PostgreSQL support. The pg_uuidv7 extension isn't always available (especially in local dev or hosted environments outside Neon / Cloud SQL).

For projects that need time-ordered UUIDs (better index locality), the README documents alternatives:

// PostgreSQL 18+ (native)
id: text().primaryKey().default(sql`uuidv7()`);

// Earlier versions (requires pg_uuidv7 extension)
id: text().primaryKey().default(sql`uuid_generate_v7()`);

Also adds casing: "snake_case" to Drizzle config to ensure camelCase TypeScript fields map correctly to snake_case database columns.

OAuth Login Flow

Simplifies the post-OAuth redirect handling:

  • Before: Complex state machine with returnUrl, redirect, loading spinners, and manual useEffect polling
  • After: Single returnTo param validated via Zod schema, router.invalidate() handles session refresh
// Search params now sanitized at parse time
const searchSchema = z.object({
  returnTo: z.string().optional()
    .transform((val) => getSafeRedirectUrl(val))
    .catch(undefined),
});

// Post-login navigation simplified
async function handleSuccess() {
  await invalidateSession(queryClient);
  await router.invalidate();
  await router.navigate({ to: search.returnTo ?? "/" });
}

Migration

For existing deployments using uuid_generate_v7():

  1. Option A: Keep existing data as-is—UUIDs are just strings, no migration needed
  2. Option B: Run bun --filter @repo/db generate to create a fresh migration reflecting the new defaults

New installations will use gen_random_uuid() automatically.

Ref #2108 #2114

Switch from uuid_generate_v7() (pg_uuidv7 extension) to gen_random_uuid()
(built-in) for universal PostgreSQL support.

Also simplifies OAuth login flow and adds Drizzle snake_case casing.

Fixes #2108, fixes #2114
@koistya koistya merged commit eda1222 into main Dec 5, 2025
10 checks passed
@koistya koistya deleted the dev branch December 5, 2025 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants