# All files / src/components/settings SchemaHealthCard.tsx

0% Statements 0/69
0% Branches 0/1
0% Functions 0/1
0% Lines 0/69

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70

     'use client'

    import { Card, CardHeader, CardTitle, CardDescription, CardContent } from '@/components/ui/card'
    import { Button } from '@/components/ui/button'
    import { Alert, AlertDescription } from '@/components/ui/alert'
    import { Warning, FirstAid, CheckCircle } from '@phosphor-icons/react'

    interface SchemaHealthCardProps {
      schemaHealth: 'unknown' | 'healthy' | 'corrupted'
      checkingSchema: boolean
      onClear: () => Promise<void>
      onCheckSchema: () => Promise<void>
    }

    export function SchemaHealthCard({
      schemaHealth,
      checkingSchema,
      onClear,
      onCheckSchema
    }: SchemaHealthCardProps) {
      if (schemaHealth === 'unknown') return null

      if (schemaHealth === 'corrupted') {
        return (
          <Card className="border-destructive bg-destructive/10">
            <CardHeader>
              <CardTitle className="flex items-center gap-2 text-destructive">
                <Warning weight="fill" size={24} />
                Schema Corruption Detected
              </CardTitle>
              <CardDescription>
                Your database schema is outdated or corrupted and needs to be repaired
              </CardDescription>
            </CardHeader>
            <CardContent className="space-y-4">
              <Alert className="border-destructive">
                <AlertDescription>
                  The database schema is missing required tables or columns (likely due to namespace feature addition).
                  This can cause errors when loading or saving snippets. Click the button below to wipe and recreate the database with the correct schema.
                </AlertDescription>
              </Alert>
              <div className="flex gap-2">
                <Button onClick={onClear} variant="destructive" className="gap-2">
                  <FirstAid weight="bold" size={16} />
                  Repair Database (Wipe & Recreate)
                </Button>
                <Button onClick={onCheckSchema} variant="outline" disabled={checkingSchema}>
                  {checkingSchema ? 'Checking...' : 'Re-check Schema'}
                </Button>
              </div>
            </CardContent>
          </Card>
        )
      }

      return (
        <Card className="border-green-600 bg-green-600/10">
          <CardHeader>
            <CardTitle className="flex items-center gap-2 text-green-600">
              <CheckCircle weight="fill" size={24} />
              Schema Healthy
            </CardTitle>
            <CardDescription>
              Your database schema is up to date and functioning correctly
            </CardDescription>
          </CardHeader>
        </Card>
      )
    }