Skip to content

Commit 24defd9

Browse files
database excesssive use fixed
1 parent 4dbc380 commit 24defd9

File tree

9 files changed

+932
-344
lines changed

9 files changed

+932
-344
lines changed

app/layout.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,7 @@ export const metadata: Metadata = {
2323
],
2424
description: 'Open-source alternative to lovable.dev, bolt.new & v0.dev. AI software engineer — live code execution, file uploads, & real-time chat blazing-fast.',
2525
icons: [
26-
{ rel: "apple-touch-icon", sizes: "180x180", url: "/apple-touch-icon.png" },
2726
{ rel: "icon", type: "image/x-icon", url: "/favicon.ico" },
28-
{ rel: "icon", type: "image/png", sizes: "32x32", url: "/icons/favicon-32x32.png" },
29-
{ rel: "icon", type: "image/png", sizes: "16x16", url: "/icons/favicon-16x16.png" },
30-
{ rel: "icon", type: "image/png", sizes: "192x192", url: "/android-chrome-192x192.png" },
31-
{ rel: "icon", type: "image/png", sizes: "512x512", url: "/android-chrome-512x512.png" }
3227
],
3328
openGraph: {
3429
title: "CodinIT.dev",
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
'use client'
2+
3+
import { useEffect, useState } from 'react'
4+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
5+
import { Button } from '@/components/ui/button'
6+
import { Alert, AlertDescription } from '@/components/ui/alert'
7+
import { Badge } from '@/components/ui/badge'
8+
import { CheckCircle, XCircle, AlertTriangle, Database, ExternalLink } from 'lucide-react'
9+
import { checkSupabaseConnection, checkEnhancedTablesExist } from '@/lib/user-settings'
10+
11+
interface TableStatus {
12+
user_profiles: boolean
13+
user_preferences: boolean
14+
user_integrations: boolean
15+
user_security_settings: boolean
16+
}
17+
18+
export default function DatabaseDiagnostic() {
19+
const [tableStatus, setTableStatus] = useState<TableStatus | null>(null)
20+
const [isChecking, setIsChecking] = useState(false)
21+
const [supabaseConnected, setSupabaseConnected] = useState(false)
22+
23+
const checkDatabaseStatus = async () => {
24+
setIsChecking(true)
25+
try {
26+
// Check Supabase connection
27+
const connected = await checkSupabaseConnection()
28+
setSupabaseConnected(connected)
29+
30+
if (connected) {
31+
// Check table existence
32+
const status = await checkEnhancedTablesExist()
33+
setTableStatus(status as unknown as TableStatus)
34+
} else {
35+
setTableStatus(null)
36+
}
37+
} catch (error) {
38+
console.error('Error checking database status:', error)
39+
setSupabaseConnected(false)
40+
setTableStatus(null)
41+
} finally {
42+
setIsChecking(false)
43+
}
44+
}
45+
46+
useEffect(() => {
47+
checkDatabaseStatus()
48+
}, [])
49+
50+
const allTablesExist = tableStatus && Object.values(tableStatus).every(exists => exists)
51+
const someTablesExist = tableStatus && Object.values(tableStatus).some(exists => exists)
52+
53+
const renderTableRow = (tableName: string, exists: boolean) => (
54+
<div key={tableName} className="flex items-center justify-between py-2">
55+
<code className="text-sm bg-muted px-2 py-1 rounded">{tableName}</code>
56+
<div className="flex items-center gap-2">
57+
{exists ? (
58+
<>
59+
<CheckCircle className="h-4 w-4 text-green-500" />
60+
<Badge variant="default" className="bg-green-100 text-green-800">Exists</Badge>
61+
</>
62+
) : (
63+
<>
64+
<XCircle className="h-4 w-4 text-red-500" />
65+
<Badge variant="destructive">Missing</Badge>
66+
</>
67+
)}
68+
</div>
69+
</div>
70+
)
71+
72+
return (
73+
<Card className="w-full max-w-2xl mx-auto">
74+
<CardHeader>
75+
<CardTitle className="flex items-center gap-2">
76+
<Database className="h-5 w-5" />
77+
Database Setup Diagnostic
78+
</CardTitle>
79+
<CardDescription>
80+
Check if your Supabase database has the required tables for user settings
81+
</CardDescription>
82+
</CardHeader>
83+
<CardContent className="space-y-6">
84+
{/* Supabase Connection Status */}
85+
<div className="space-y-2">
86+
<h3 className="text-sm font-medium">Supabase Connection</h3>
87+
<div className="flex items-center gap-2">
88+
{supabaseConnected ? (
89+
<>
90+
<CheckCircle className="h-4 w-4 text-green-500" />
91+
<span className="text-sm">Connected</span>
92+
</>
93+
) : (
94+
<>
95+
<XCircle className="h-4 w-4 text-red-500" />
96+
<span className="text-sm">Not connected or configuration error</span>
97+
</>
98+
)}
99+
</div>
100+
</div>
101+
102+
{/* Table Status */}
103+
{tableStatus && (
104+
<div className="space-y-4">
105+
<div className="flex items-center justify-between">
106+
<h3 className="text-sm font-medium">Required Tables</h3>
107+
<Button
108+
variant="outline"
109+
size="sm"
110+
onClick={checkDatabaseStatus}
111+
disabled={isChecking}
112+
>
113+
{isChecking ? 'Checking...' : 'Refresh'}
114+
</Button>
115+
</div>
116+
117+
<div className="space-y-1 border rounded-lg p-3">
118+
{Object.entries(tableStatus).map(([table, exists]) =>
119+
renderTableRow(table, exists)
120+
)}
121+
</div>
122+
</div>
123+
)}
124+
125+
{/* Status Alerts */}
126+
{!supabaseConnected && (
127+
<Alert variant="destructive">
128+
<AlertTriangle className="h-4 w-4" />
129+
<AlertDescription>
130+
Supabase is not properly configured. Check your environment variables:
131+
<ul className="mt-2 space-y-1">
132+
<li><code>NEXT_PUBLIC_SUPABASE_URL</code></li>
133+
<li><code>NEXT_PUBLIC_SUPABASE_ANON_KEY</code></li>
134+
</ul>
135+
</AlertDescription>
136+
</Alert>
137+
)}
138+
139+
{supabaseConnected && tableStatus && !allTablesExist && (
140+
<Alert variant="destructive">
141+
<AlertTriangle className="h-4 w-4" />
142+
<AlertDescription>
143+
{!someTablesExist
144+
? "Required database tables are missing. You need to run the database migration."
145+
: "Some database tables are missing. You may need to update your database migration."
146+
}
147+
</AlertDescription>
148+
</Alert>
149+
)}
150+
151+
{allTablesExist && (
152+
<Alert>
153+
<CheckCircle className="h-4 w-4" />
154+
<AlertDescription>
155+
All required database tables exist! Your user settings should work properly.
156+
</AlertDescription>
157+
</Alert>
158+
)}
159+
160+
{/* Setup Instructions */}
161+
{supabaseConnected && !allTablesExist && (
162+
<div className="space-y-4">
163+
<h3 className="text-sm font-medium">Setup Instructions</h3>
164+
<div className="prose prose-sm max-w-none">
165+
<ol className="space-y-2">
166+
<li>
167+
Open your Supabase dashboard
168+
<Button variant="link" className="p-0 h-auto ml-2" asChild>
169+
<a href="https://app.supabase.com/projects" target="_blank" rel="noopener noreferrer">
170+
<ExternalLink className="h-3 w-3 ml-1" />
171+
</a>
172+
</Button>
173+
</li>
174+
<li>Go to SQL Editor in your project</li>
175+
<li>Create a new query and paste the complete database migration SQL</li>
176+
<li>Run the migration to create all required tables</li>
177+
<li>Return here and click &quot;Refresh&quot; to verify the setup</li>
178+
</ol>
179+
</div>
180+
</div>
181+
)}
182+
183+
{/* Migration SQL Link */}
184+
{!allTablesExist && (
185+
<div className="border-t pt-4">
186+
<p className="text-sm text-muted-foreground">
187+
Need the migration SQL? The complete database schema was provided in the previous response.
188+
Copy and run it in your Supabase SQL Editor.
189+
</p>
190+
</div>
191+
)}
192+
</CardContent>
193+
</Card>
194+
)
195+
}

components/logo2.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use client'
2+
3+
import Image from 'next/image'
4+
import { useTheme } from 'next-themes'
5+
import { ComponentProps } from 'react'
6+
7+
export default function Icon(
8+
props: Omit<ComponentProps<typeof Image>, 'src' | 'alt'>
9+
) {
10+
const { theme } = useTheme()
11+
const src = theme === 'light' ? '/icon.png' : '/icon-dark.png'
12+
const { width, style } = props
13+
14+
return (
15+
<Image
16+
src={src}
17+
alt="icon"
18+
{...props}
19+
style={{ ...style, width, height: 'auto' }}
20+
/>
21+
)
22+
}

components/navbar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
import { Session } from '@supabase/supabase-js'
2222
import { ArrowRight, LogOut, Trash, Undo, Settings, Menu } from 'lucide-react'
2323
import Link from 'next/link'
24-
import Image from 'next/image'
24+
import Icon from './logo2'
2525

2626
export function NavBar({
2727
session,
@@ -118,7 +118,7 @@ export function NavBar({
118118
window.open('https://codinit.dev/blog/codinit-beta', '_blank')
119119
}}
120120
>
121-
<Logo
121+
<Icon
122122
width={16}
123123
height={16}
124124
className="mr-2 text-muted-foreground"

lib/auth.ts

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -73,33 +73,7 @@ export function useAuth(
7373
}
7474

7575
if (_event === 'SIGNED_IN' && !recovery) {
76-
getUserTeam(session as Session).then((team) => {
77-
if (team) {
78-
setUserTeam(team)
79-
} else {
80-
const teamId = randomString(10)
81-
supabase!
82-
.from('teams')
83-
.insert({
84-
id: teamId,
85-
name: 'My Team',
86-
tier: 'free',
87-
email: session?.user.email,
88-
})
89-
.then(() => {
90-
supabase!
91-
.from('users_teams')
92-
.insert({
93-
user_id: session?.user.id,
94-
team_id: teamId,
95-
is_default: true,
96-
})
97-
.then(() => {
98-
getUserTeam(session as Session).then(setUserTeam)
99-
})
100-
})
101-
}
102-
})
76+
getUserTeam(session as Session).then(setUserTeam)
10377
setAuthDialog(false)
10478
if (!session?.user.user_metadata.is_fragments_user) {
10579
supabase?.auth.updateUser({

0 commit comments

Comments
 (0)