From a32d620d6c6a8477e64b45cfbd3b030370b12f65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fatih=20Kadir=20Ak=C4=B1n?= Date: Mon, 12 Jan 2026 00:56:55 +0300 Subject: [PATCH] chore(prisma): update schema to include direct URL for migrations --- .env.example | 2 ++ prisma/schema.prisma | 5 +++-- src/components/ui/masonry.tsx | 24 ++++++++++-------------- src/lib/db.ts | 9 ++++++++- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/.env.example b/.env.example index e8928576..f9fcc46f 100644 --- a/.env.example +++ b/.env.example @@ -2,6 +2,8 @@ # Add connection_limit and pool_timeout for serverless/production environments: # Example: ?schema=public&connection_limit=5&pool_timeout=10 DATABASE_URL="postgresql://postgres:postgres@localhost:5432/prompts_chat?schema=public" +# Direct URL for migrations (bypasses connection pooler) - used by Neon, Supabase, PlanetScale +# DIRECT_URL="postgresql://postgres:postgres@localhost:5432/prompts_chat?schema=public" # NextAuth NEXTAUTH_URL="http://localhost:3000" diff --git a/prisma/schema.prisma b/prisma/schema.prisma index ccd56bfc..c2999099 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -3,8 +3,9 @@ generator client { } datasource db { - provider = "postgresql" - url = env("DATABASE_URL") + provider = "postgresql" + url = env("DATABASE_URL") + directUrl = env("DIRECT_URL") } model User { diff --git a/src/components/ui/masonry.tsx b/src/components/ui/masonry.tsx index bf41590d..6a901584 100644 --- a/src/components/ui/masonry.tsx +++ b/src/components/ui/masonry.tsx @@ -22,11 +22,10 @@ export function Masonry({ const containerRef = useRef(null); const [columns, setColumns] = useState(columnCount.default); const [containerHeight, setContainerHeight] = useState(0); + const [containerWidth, setContainerWidth] = useState(0); const [isRTL, setIsRTL] = useState(false); + const [positions, setPositions] = useState>(new Map()); const itemRefs = useRef>(new Map()); - const positionsRef = useRef>(new Map()); - const [, forceUpdate] = useState(0); - const prevChildrenLengthRef = useRef(0); // Detect RTL direction useEffect(() => { @@ -63,9 +62,12 @@ export function Masonry({ const calculatePositions = useCallback(() => { if (!containerRef.current) return; - const containerWidth = containerRef.current.offsetWidth; - const columnWidth = (containerWidth - gap * (columns - 1)) / columns; + const width = containerRef.current.offsetWidth; + setContainerWidth(width); + + const columnWidth = (width - gap * (columns - 1)) / columns; const columnHeights = new Array(columns).fill(0); + const newPositions = new Map(); children.forEach((_, index) => { const itemEl = itemRefs.current.get(index); @@ -76,7 +78,7 @@ export function Masonry({ const x = shortestColumn * (columnWidth + gap); const y = columnHeights[shortestColumn]; - positionsRef.current.set(index, { x, y }); + newPositions.set(index, { x, y }); // Update column height const itemHeight = itemEl.offsetHeight; @@ -87,18 +89,13 @@ export function Masonry({ if (newHeight > 0) { setContainerHeight(newHeight); } - forceUpdate(n => n + 1); + setPositions(newPositions); }, [children, columns, gap]); // Recalculate when new children are added useEffect(() => { - const currentLength = children.length; - const prevLength = prevChildrenLengthRef.current; - // Calculate positions after a brief delay for new items to render const timer = setTimeout(calculatePositions, 10); - prevChildrenLengthRef.current = currentLength; - return () => clearTimeout(timer); }, [children.length, calculatePositions]); @@ -120,7 +117,6 @@ export function Masonry({ return () => observer.disconnect(); }, [calculatePositions, children.length]); - const containerWidth = containerRef.current?.offsetWidth || 0; const columnWidth = containerWidth > 0 ? (containerWidth - gap * (columns - 1)) / columns : 0; @@ -132,7 +128,7 @@ export function Masonry({ style={{ height: containerHeight > 0 ? containerHeight : "auto" }} > {children.map((child, index) => { - const position = positionsRef.current.get(index); + const position = positions.get(index); const hasPosition = position !== undefined; return (