|
| 1 | +import { SUPABASE_SCHEMAS } from '@database.build/deploy/supabase' |
| 2 | +import { Results } from '@electric-sql/pglite' |
| 3 | +import { sql } from '@electric-sql/pglite/template' |
| 4 | +import { join } from '~/lib/db' |
| 5 | +import { useAsyncMemo } from '~/lib/hooks' |
| 6 | +import { useApp } from '../app-provider' |
| 7 | +import { Loader } from 'lucide-react' |
| 8 | + |
| 9 | +export type SchemaOverlapWarningProps = { |
| 10 | + databaseId: string |
| 11 | +} |
| 12 | + |
| 13 | +export function SchemaOverlapWarning({ databaseId }: SchemaOverlapWarningProps) { |
| 14 | + const { dbManager } = useApp() |
| 15 | + |
| 16 | + const { value: overlappingSchemas, loading: isLoadingSchemas } = useAsyncMemo(async () => { |
| 17 | + if (!dbManager) { |
| 18 | + throw new Error('dbManager is not available') |
| 19 | + } |
| 20 | + |
| 21 | + const db = await dbManager.getDbInstance(databaseId) |
| 22 | + |
| 23 | + console.log(SUPABASE_SCHEMAS) |
| 24 | + |
| 25 | + const { rows }: Results<{ schema_name: string }> = await db.sql` |
| 26 | + SELECT schema_name |
| 27 | + FROM information_schema.schemata |
| 28 | + WHERE schema_name IN (${join( |
| 29 | + SUPABASE_SCHEMAS.map((s) => sql`${s}`), |
| 30 | + ',' |
| 31 | + )}) |
| 32 | + ` |
| 33 | + |
| 34 | + return rows.map((row) => row.schema_name) |
| 35 | + }, [databaseId]) |
| 36 | + |
| 37 | + if (isLoadingSchemas || !overlappingSchemas) { |
| 38 | + return ( |
| 39 | + <Loader |
| 40 | + className="animate-spin self-center justify-self-center my-4" |
| 41 | + size={36} |
| 42 | + strokeWidth={0.75} |
| 43 | + /> |
| 44 | + ) |
| 45 | + } |
| 46 | + |
| 47 | + if (overlappingSchemas.length > 0) { |
| 48 | + return ( |
| 49 | + <div className="flex flex-col gap-2 rounded-md border-destructive bg-destructive/25 p-4 mb-2"> |
| 50 | + The following Supabase schemas were detected in your browser database and will be excluded |
| 51 | + from the deployment: |
| 52 | + <div className="prose text-sm"> |
| 53 | + <ul className="my-0"> |
| 54 | + {overlappingSchemas.map((schema) => ( |
| 55 | + <li key={schema} className="my-0"> |
| 56 | + <code>{schema}</code> |
| 57 | + </li> |
| 58 | + ))} |
| 59 | + </ul> |
| 60 | + </div> |
| 61 | + </div> |
| 62 | + ) |
| 63 | + } |
| 64 | + |
| 65 | + return null |
| 66 | +} |
0 commit comments