mirror of
https://github.com/supabase/supabase.git
synced 2026-05-07 17:30:25 -04:00
55bdf3cebf
## Context For database extensions, previously dashboard would fire a separate call just to retrieve the "default schema" for an extension via `useDatabaseExtensionDefaultSchemaQuery` from the `pg_available_extension_versions` table (the `schema` from this table implies where the extension will be installed in) ## Changes involved Am updating the `useDatabaseExtensionsQuery` to use a custom studio SQL that will fetch this data in one request via a `LEFT JOIN`, so dashboard no longer needs to fire a request to `pg_available_extension_versions` each time we open the `EnableExtensionModal` since all the info we need is loaded up front. Have also validated that the cost of the custom studio SQL is low (6.8, via explain analyze) so performance wise on the project's DB should be okay. This will then also allow us to correctly render the "default schema" of the extensions in the new Install Integration Sheet now that we have that information up front. ## Misc fix Also fixed a small issue on the database extensions page whereby if you searched for an extension that's hidden (e.g pg_tle), there's no "No results" UI state showing up <img width="1112" height="319" alt="image" src="https://github.com/user-attachments/assets/eb488117-2a24-4317-ad73-1d636f9b1bc8" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Per-extension default schema detection surfaced across install flows; default schema options added to selectors when applicable. * **Bug Fixes** * Hidden extensions filtered out earlier so they no longer appear in lists. * Install button now correctly disables when required extensions are missing. * **Refactor** * Consolidated extensions metadata retrieval and simplified schema selection/validation logic; UI text formatting standardized. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
48 lines
1.6 KiB
TypeScript
48 lines
1.6 KiB
TypeScript
import { getEnableDatabaseExtensionSQL } from '@supabase/pg-meta'
|
|
|
|
import { DatabaseExtension } from '@/data/database-extensions/database-extensions-query'
|
|
|
|
export const getEnableExtensionsSQL = ({
|
|
extensions,
|
|
extensionsSchema,
|
|
}: {
|
|
extensions: DatabaseExtension[]
|
|
extensionsSchema: {
|
|
[key: string]: { schema: string; value: string | undefined }
|
|
}
|
|
}) => {
|
|
return extensions
|
|
.map((extension) => {
|
|
/**
|
|
* [Joshen] Hard-coding pg_cron here as this is enforced on our end (Not via pg_available_extension_versions)
|
|
* Also temp hardcoding to `extensions` for now, but we should be retrieving the default schema from `pg_available_extension_versions`
|
|
* Am checking with pg-meta team whether we can just return that data directly from the /pg-meta/extensions endpoint, rather
|
|
* than using dashboard's `useDatabaseExtensionDefaultSchemaQuery` - we can technically save a query if so
|
|
*/
|
|
const { name, default_version: version } = extension
|
|
const createSchema = extensionsSchema[name].schema === 'custom'
|
|
const schema =
|
|
name === 'pg_cron'
|
|
? 'pg_catalog'
|
|
: createSchema
|
|
? (extensionsSchema[name].value as string)
|
|
: extensionsSchema[name].schema
|
|
|
|
return getEnableDatabaseExtensionSQL({
|
|
schema,
|
|
name,
|
|
version,
|
|
cascade: true,
|
|
createSchema,
|
|
})
|
|
})
|
|
.filter(Boolean)
|
|
.join('\n\n')
|
|
.trim()
|
|
}
|
|
|
|
export const getExtensionDefaultSchema = (ext?: DatabaseExtension) => {
|
|
if (!ext) return null
|
|
return ext.name === 'pg_cron' ? 'pg_catalog' : ext.default_version_schema
|
|
}
|