From 1c5932769cc785c241d9cd57f1031d0433a6fd72 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 31 Oct 2025 00:16:58 +0000 Subject: [PATCH] fix mirgation db issue --- .env | 6 +++--- db/migrations/0000_init.sql | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/.env b/.env index 1e44d2cca..4742b6cf3 100644 --- a/.env +++ b/.env @@ -19,12 +19,12 @@ GOOGLE_CLOUD_REGION=us-central1 # Database # https://console.neon.tech/ -DATABASE_URL=postgres://postgres:postgres@localhost:5432/example +DATABASE_URL=postgresql://postgres:ninja@localhost:5432/example # Cloudflare Hyperdrive for local development # https://developers.cloudflare.com/hyperdrive/ -WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE_CACHED=postgres://postgres:postgres@localhost:5432/example -WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE_DIRECT=postgres://postgres:postgres@localhost:5432/example +WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE_CACHED=postgresql://postgres:ninja@localhost:5432/example +WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE_DIRECT=postgresql://postgres:ninja@localhost:5432/example # Better Auth # bunx @better-auth/cli@latest secret diff --git a/db/migrations/0000_init.sql b/db/migrations/0000_init.sql index 5f79ef5ca..8fa06b42b 100644 --- a/db/migrations/0000_init.sql +++ b/db/migrations/0000_init.sql @@ -1,3 +1,26 @@ +-- Enable UUID extension for uuid generation +CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; + +-- Create uuid_generate_v7 function (UUIDv7 with timestamp ordering) +-- This provides better performance for indexed primary keys compared to UUIDv4 +CREATE OR REPLACE FUNCTION uuid_generate_v7() +RETURNS uuid +AS $$ +DECLARE + unix_ts_ms bytea; + uuid_bytes bytea; +BEGIN + unix_ts_ms = substring(int8send(floor(extract(epoch from clock_timestamp()) * 1000)::bigint) from 3); + uuid_bytes = uuid_send(gen_random_uuid()); + uuid_bytes = overlay(uuid_bytes placing unix_ts_ms from 1 for 6); + uuid_bytes = set_byte(uuid_bytes, 6, (b'0111' || get_byte(uuid_bytes, 6)::bit(4))::bit(8)::int); + RETURN encode(uuid_bytes, 'hex')::uuid; +END +$$ +LANGUAGE plpgsql +VOLATILE; + +--> statement-breakpoint CREATE TABLE "invitation" ( "id" text PRIMARY KEY DEFAULT uuid_generate_v7() NOT NULL, "email" text NOT NULL,