mirror of
https://github.com/f/awesome-chatgpt-prompts.git
synced 2026-03-03 03:07:00 +00:00
chore(prisma): update schema to include direct URL for migrations
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
# Add connection_limit and pool_timeout for serverless/production environments:
|
# Add connection_limit and pool_timeout for serverless/production environments:
|
||||||
# Example: ?schema=public&connection_limit=5&pool_timeout=10
|
# Example: ?schema=public&connection_limit=5&pool_timeout=10
|
||||||
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/prompts_chat?schema=public"
|
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
|
||||||
NEXTAUTH_URL="http://localhost:3000"
|
NEXTAUTH_URL="http://localhost:3000"
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ generator client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
datasource db {
|
datasource db {
|
||||||
provider = "postgresql"
|
provider = "postgresql"
|
||||||
url = env("DATABASE_URL")
|
url = env("DATABASE_URL")
|
||||||
|
directUrl = env("DIRECT_URL")
|
||||||
}
|
}
|
||||||
|
|
||||||
model User {
|
model User {
|
||||||
|
|||||||
@@ -22,11 +22,10 @@ export function Masonry({
|
|||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
const [columns, setColumns] = useState(columnCount.default);
|
const [columns, setColumns] = useState(columnCount.default);
|
||||||
const [containerHeight, setContainerHeight] = useState(0);
|
const [containerHeight, setContainerHeight] = useState(0);
|
||||||
|
const [containerWidth, setContainerWidth] = useState(0);
|
||||||
const [isRTL, setIsRTL] = useState(false);
|
const [isRTL, setIsRTL] = useState(false);
|
||||||
|
const [positions, setPositions] = useState<Map<number, { x: number; y: number }>>(new Map());
|
||||||
const itemRefs = useRef<Map<number, HTMLDivElement>>(new Map());
|
const itemRefs = useRef<Map<number, HTMLDivElement>>(new Map());
|
||||||
const positionsRef = useRef<Map<number, { x: number; y: number }>>(new Map());
|
|
||||||
const [, forceUpdate] = useState(0);
|
|
||||||
const prevChildrenLengthRef = useRef(0);
|
|
||||||
|
|
||||||
// Detect RTL direction
|
// Detect RTL direction
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -63,9 +62,12 @@ export function Masonry({
|
|||||||
const calculatePositions = useCallback(() => {
|
const calculatePositions = useCallback(() => {
|
||||||
if (!containerRef.current) return;
|
if (!containerRef.current) return;
|
||||||
|
|
||||||
const containerWidth = containerRef.current.offsetWidth;
|
const width = containerRef.current.offsetWidth;
|
||||||
const columnWidth = (containerWidth - gap * (columns - 1)) / columns;
|
setContainerWidth(width);
|
||||||
|
|
||||||
|
const columnWidth = (width - gap * (columns - 1)) / columns;
|
||||||
const columnHeights = new Array(columns).fill(0);
|
const columnHeights = new Array(columns).fill(0);
|
||||||
|
const newPositions = new Map<number, { x: number; y: number }>();
|
||||||
|
|
||||||
children.forEach((_, index) => {
|
children.forEach((_, index) => {
|
||||||
const itemEl = itemRefs.current.get(index);
|
const itemEl = itemRefs.current.get(index);
|
||||||
@@ -76,7 +78,7 @@ export function Masonry({
|
|||||||
const x = shortestColumn * (columnWidth + gap);
|
const x = shortestColumn * (columnWidth + gap);
|
||||||
const y = columnHeights[shortestColumn];
|
const y = columnHeights[shortestColumn];
|
||||||
|
|
||||||
positionsRef.current.set(index, { x, y });
|
newPositions.set(index, { x, y });
|
||||||
|
|
||||||
// Update column height
|
// Update column height
|
||||||
const itemHeight = itemEl.offsetHeight;
|
const itemHeight = itemEl.offsetHeight;
|
||||||
@@ -87,18 +89,13 @@ export function Masonry({
|
|||||||
if (newHeight > 0) {
|
if (newHeight > 0) {
|
||||||
setContainerHeight(newHeight);
|
setContainerHeight(newHeight);
|
||||||
}
|
}
|
||||||
forceUpdate(n => n + 1);
|
setPositions(newPositions);
|
||||||
}, [children, columns, gap]);
|
}, [children, columns, gap]);
|
||||||
|
|
||||||
// Recalculate when new children are added
|
// Recalculate when new children are added
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const currentLength = children.length;
|
|
||||||
const prevLength = prevChildrenLengthRef.current;
|
|
||||||
|
|
||||||
// Calculate positions after a brief delay for new items to render
|
// Calculate positions after a brief delay for new items to render
|
||||||
const timer = setTimeout(calculatePositions, 10);
|
const timer = setTimeout(calculatePositions, 10);
|
||||||
prevChildrenLengthRef.current = currentLength;
|
|
||||||
|
|
||||||
return () => clearTimeout(timer);
|
return () => clearTimeout(timer);
|
||||||
}, [children.length, calculatePositions]);
|
}, [children.length, calculatePositions]);
|
||||||
|
|
||||||
@@ -120,7 +117,6 @@ export function Masonry({
|
|||||||
return () => observer.disconnect();
|
return () => observer.disconnect();
|
||||||
}, [calculatePositions, children.length]);
|
}, [calculatePositions, children.length]);
|
||||||
|
|
||||||
const containerWidth = containerRef.current?.offsetWidth || 0;
|
|
||||||
const columnWidth = containerWidth > 0
|
const columnWidth = containerWidth > 0
|
||||||
? (containerWidth - gap * (columns - 1)) / columns
|
? (containerWidth - gap * (columns - 1)) / columns
|
||||||
: 0;
|
: 0;
|
||||||
@@ -132,7 +128,7 @@ export function Masonry({
|
|||||||
style={{ height: containerHeight > 0 ? containerHeight : "auto" }}
|
style={{ height: containerHeight > 0 ? containerHeight : "auto" }}
|
||||||
>
|
>
|
||||||
{children.map((child, index) => {
|
{children.map((child, index) => {
|
||||||
const position = positionsRef.current.get(index);
|
const position = positions.get(index);
|
||||||
const hasPosition = position !== undefined;
|
const hasPosition = position !== undefined;
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -11,6 +11,13 @@ export const db =
|
|||||||
process.env.NODE_ENV === "development"
|
process.env.NODE_ENV === "development"
|
||||||
? ["query", "error", "warn"]
|
? ["query", "error", "warn"]
|
||||||
: ["error"],
|
: ["error"],
|
||||||
|
datasourceUrl: process.env.DATABASE_URL,
|
||||||
});
|
});
|
||||||
|
|
||||||
globalForPrisma.prisma = db;
|
// Prevent connection pool exhaustion in serverless environments
|
||||||
|
if (process.env.NODE_ENV !== "production") {
|
||||||
|
globalForPrisma.prisma = db;
|
||||||
|
} else {
|
||||||
|
// In production, always use the same instance to avoid connection issues
|
||||||
|
globalForPrisma.prisma = db;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user