feat(db-*): return database name to unsanitized config (#11913)

You can access the database name from `sanitizedConfig.db.name`. But
currently, it' not possible to access the db name from the unsanitized
config.

Plugins only have access to the unsanitized config. This change allows
db adapters to return the db name early, which will allow plugins to
conditionally initialize db-specific functionality
This commit is contained in:
Alessio Gravili
2025-03-31 12:57:17 -06:00
committed by GitHub
parent 96289bf555
commit a083d47368
5 changed files with 10 additions and 0 deletions

View File

@@ -273,6 +273,7 @@ export function mongooseAdapter({
} }
return { return {
name: 'mongoose',
allowIDOnCreate, allowIDOnCreate,
defaultIDType: 'text', defaultIDType: 'text',
init: adapter, init: adapter,

View File

@@ -208,6 +208,7 @@ export function postgresAdapter(args: Args): DatabaseAdapterObj<PostgresAdapter>
} }
return { return {
name: 'postgres',
allowIDOnCreate, allowIDOnCreate,
defaultIDType: payloadIDType, defaultIDType: payloadIDType,
init: adapter, init: adapter,

View File

@@ -193,6 +193,7 @@ export function sqliteAdapter(args: Args): DatabaseAdapterObj<SQLiteAdapter> {
} }
return { return {
name: 'sqlite',
allowIDOnCreate, allowIDOnCreate,
defaultIDType: payloadIDType, defaultIDType: payloadIDType,
init: adapter, init: adapter,

View File

@@ -205,6 +205,7 @@ export function vercelPostgresAdapter(args: Args = {}): DatabaseAdapterObj<Verce
} }
return { return {
name: 'postgres',
allowIDOnCreate, allowIDOnCreate,
defaultIDType: payloadIDType, defaultIDType: payloadIDType,
init: adapter, init: adapter,

View File

@@ -642,6 +642,12 @@ export type DatabaseAdapterResult<T = BaseDatabaseAdapter> = {
allowIDOnCreate?: boolean allowIDOnCreate?: boolean
defaultIDType: 'number' | 'text' defaultIDType: 'number' | 'text'
init: (args: { payload: Payload }) => T init: (args: { payload: Payload }) => T
/**
* The name of the database adapter. For example, "postgres" or "mongoose".
*
* @todo make required in 4.0
*/
name?: string
} }
export type DBIdentifierName = export type DBIdentifierName =