Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions db/migrations/0000_init.sql
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Loading