mirror of
https://github.com/supabase/supabase.git
synced 2026-10-11 04:15:04 +03:00
## Summary - Converts ~27 `executeSql` call sites in `apps/studio/data/**` to build SQL through `safeSql` / `ident` / `literal` / `keyword` / `joinSqlFragments` instead of raw template-string interpolation. - Tightens the `useDatabaseCronJobCreateMutation` and `useDatabaseEventTriggerCreateMutation` `sql`/`query` parameter types from `string` to `SafeSqlFragment` (callers already produce one). - Updates `getDeleteEnumeratedTypeSQL` in `packages/pg-meta` to return `SafeSqlFragment`. - Fixes a bug noticed while testing where Queues integration does not correctly handle queues with uppercase names. ## Pages to manually test - Integrations > Cron Jobs - Integrations > Queues - Database > Triggers > Event Triggers - Database > Indexes - Reports > Query Performance - Storage <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Queue lookups now correctly handle case-insensitive queue names. * Queue table references are now properly managed and consistently applied throughout the queue management interface. * Improved queue name display normalization in the user interface. * **Chores** * Enhanced SQL query safety across the database layer through parameterized query construction and safer templating approaches. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
116 lines
3.7 KiB
TypeScript
116 lines
3.7 KiB
TypeScript
import dayjs from 'dayjs'
|
|
import { includes, sortBy } from 'lodash'
|
|
import { Check, ChevronRight, Loader2, X } from 'lucide-react'
|
|
import { useRouter } from 'next/router'
|
|
|
|
import { pgmqQueueTable } from './Queues.utils'
|
|
import Table from '@/components/to-be-cleaned/Table'
|
|
import { useQueuesMetricsQuery } from '@/data/database-queues/database-queues-metrics-query'
|
|
import { PostgresQueue } from '@/data/database-queues/database-queues-query'
|
|
import { useTablesQuery } from '@/data/tables/tables-query'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { DATETIME_FORMAT } from '@/lib/constants'
|
|
|
|
interface QueuesRowsProps {
|
|
queues: PostgresQueue[]
|
|
filterString: string
|
|
}
|
|
|
|
const QueueRow = ({ queue }: { queue: PostgresQueue }) => {
|
|
const router = useRouter()
|
|
const { data: selectedProject } = useSelectedProjectQuery()
|
|
|
|
const { data: queueTables } = useTablesQuery({
|
|
projectRef: selectedProject?.ref,
|
|
connectionString: selectedProject?.connectionString,
|
|
schema: 'pgmq',
|
|
})
|
|
const queueTable = queueTables?.find((x) => x.name === pgmqQueueTable(queue.queue_name))
|
|
const isRlsEnabled = !!queueTable?.rls_enabled
|
|
|
|
const { data: metrics, isPending: isLoading } = useQueuesMetricsQuery(
|
|
{
|
|
queueName: queue.queue_name,
|
|
projectRef: selectedProject?.ref,
|
|
connectionString: selectedProject?.connectionString,
|
|
},
|
|
{
|
|
staleTime: 30 * 1000, // 30 seconds, talk with Oli whether this is ok to call every minute
|
|
}
|
|
)
|
|
|
|
const type = queue.is_partitioned ? 'Partitioned' : queue.is_unlogged ? 'Unlogged' : 'Basic'
|
|
|
|
return (
|
|
<Table.tr
|
|
key={queue.queue_name}
|
|
onClick={() => {
|
|
router.push(
|
|
`/project/${selectedProject?.ref}/integrations/queues/queues/${queue.queue_name}`
|
|
)
|
|
}}
|
|
>
|
|
<Table.td className="truncate">
|
|
<p title={queue.queue_name}>{queue.queue_name}</p>
|
|
</Table.td>
|
|
<Table.td className="table-cell overflow-auto">
|
|
<p title={type.toLocaleLowerCase()} className="truncate">
|
|
{type}
|
|
</p>
|
|
</Table.td>
|
|
<Table.td className="table-cell">
|
|
<div className="flex justify-center">
|
|
{isRlsEnabled ? <Check size={14} className="text-brand" /> : <X size={14} />}
|
|
</div>
|
|
</Table.td>
|
|
<Table.td className="table-cell">
|
|
<p title={queue.created_at}>{dayjs(queue.created_at).format(DATETIME_FORMAT)}</p>
|
|
</Table.td>
|
|
<Table.td className="table-cell">
|
|
<div className="flex justify-center">
|
|
{isLoading ? (
|
|
<Loader2 className="animate-spin" size={16} />
|
|
) : (
|
|
<p>
|
|
{metrics?.queue_length} {metrics?.method === 'estimated' ? '(Approximate)' : null}
|
|
</p>
|
|
)}
|
|
</div>
|
|
</Table.td>
|
|
<Table.td>
|
|
<div className="flex items-center justify-end">
|
|
<ChevronRight size="18" />
|
|
</div>
|
|
</Table.td>
|
|
</Table.tr>
|
|
)
|
|
}
|
|
|
|
export const QueuesRows = ({ queues: fetchedQueues, filterString }: QueuesRowsProps) => {
|
|
const filteredQueues = fetchedQueues.filter((x) =>
|
|
includes(x.queue_name.toLowerCase(), filterString.toLowerCase())
|
|
)
|
|
const queues = sortBy(filteredQueues, (func) => func.queue_name.toLocaleLowerCase())
|
|
|
|
if (queues.length === 0 && filterString.length > 0) {
|
|
return (
|
|
<Table.tr>
|
|
<Table.td colSpan={5}>
|
|
<p className="text-sm text-foreground">No results found</p>
|
|
<p className="text-sm text-foreground-light">
|
|
Your search for "{filterString}" did not return any results
|
|
</p>
|
|
</Table.td>
|
|
</Table.tr>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<>
|
|
{queues.map((q) => (
|
|
<QueueRow key={q.queue_name} queue={q} />
|
|
))}
|
|
</>
|
|
)
|
|
}
|