Files
supabase/e2e/studio/utils/db/queries.ts
Charis 76b767c5e1 test(studio): add db utils for checking database state (#42533)
Test utilities

## What is the current behavior?

E2E tests that need to verify database state go through the SQL Editor,
which is unnecessarily slow and prone to future breakage.

## What is the new behavior?

Adds shared db utils for checking database state in Studio E2E tests by
querying the database directly. Refactors API access tests to use the
new utilities.

## Summary by CodeRabbit

* **Tests**
* Refactored API access privilege verification to use direct database
queries instead of SQL editor interaction.
* Added database utility functions for e2e tests to query table
existence and access privileges.
  * Updated test signatures to simplify privilege verification calls.
2026-02-05 17:46:33 -05:00

20 lines
596 B
TypeScript

import { query } from './client.js'
/**
* Check if a table exists in the specified schema.
*
* @param schema - The schema name (e.g., 'public')
* @param tableName - The table name to check
* @returns true if the table exists, false otherwise
*/
export async function tableExists(schema: string, tableName: string): Promise<boolean> {
const result = await query<{ exists: boolean }>(
`SELECT EXISTS (
SELECT 1 FROM information_schema.tables
WHERE table_schema = $1 AND table_name = $2
) as exists`,
[schema, tableName]
)
return result[0]?.exists ?? false
}