chore: changes postgres interface client arg to pool and adds poolOptions
This commit is contained in:
@@ -17,13 +17,14 @@ export const connect: Connect = async function connect(this: PostgresAdapter, pa
|
||||
}
|
||||
|
||||
try {
|
||||
this.pool = new Pool(this.client)
|
||||
this.pool = new Pool(this.poolOptions)
|
||||
await this.pool.connect()
|
||||
|
||||
this.drizzle = drizzle(this.pool, { schema: this.schema })
|
||||
if (process.env.PAYLOAD_DROP_DATABASE === 'true') {
|
||||
this.payload.logger.info('---- DROPPING TABLES ----')
|
||||
await this.drizzle.execute(sql`drop schema public cascade;\ncreate schema public;`)
|
||||
await this.drizzle.execute(sql`drop schema public cascade;
|
||||
create schema public;`)
|
||||
this.payload.logger.info('---- DROPPED TABLES ----')
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
@@ -5,8 +5,6 @@ import { createDatabaseAdapter } from 'payload/database'
|
||||
|
||||
import type { Args, PostgresAdapter, PostgresAdapterResult } from './types'
|
||||
|
||||
export type { MigrateDownArgs, MigrateUpArgs } from './types'
|
||||
|
||||
import { connect } from './connect'
|
||||
import { create } from './create'
|
||||
import { createGlobal } from './createGlobal'
|
||||
@@ -36,6 +34,8 @@ import { updateGlobal } from './updateGlobal'
|
||||
import { updateGlobalVersion } from './updateGlobalVersion'
|
||||
import { updateVersion } from './updateVersion'
|
||||
|
||||
export type { MigrateDownArgs, MigrateUpArgs } from './types'
|
||||
|
||||
export function postgresAdapter(args: Args): PostgresAdapterResult {
|
||||
function adapter({ payload }: { payload: Payload }) {
|
||||
const migrationDir = args.migrationDir || path.resolve(process.cwd(), 'src/migrations')
|
||||
@@ -44,13 +44,13 @@ export function postgresAdapter(args: Args): PostgresAdapterResult {
|
||||
extendViteConfig(payload.config)
|
||||
|
||||
return createDatabaseAdapter<PostgresAdapter>({
|
||||
...args,
|
||||
name: 'postgres',
|
||||
|
||||
// Postgres-specific
|
||||
drizzle: undefined,
|
||||
enums: {},
|
||||
pool: undefined,
|
||||
poolOptions: args.pool,
|
||||
relations: {},
|
||||
schema: {},
|
||||
sessions: {},
|
||||
|
||||
@@ -14,9 +14,8 @@ import type { Pool, PoolConfig } from 'pg'
|
||||
export type DrizzleDB = NodePgDatabase<Record<string, unknown>>
|
||||
|
||||
export type Args = {
|
||||
client: PoolConfig
|
||||
migrationDir?: string
|
||||
migrationName?: string
|
||||
pool: PoolConfig
|
||||
}
|
||||
|
||||
export type GenericColumn = PgColumn<
|
||||
@@ -45,11 +44,11 @@ export type DrizzleTransaction = PgTransaction<
|
||||
ExtractTablesWithRelations<Record<string, unknown>>
|
||||
>
|
||||
|
||||
export type PostgresAdapter = BaseDatabaseAdapter &
|
||||
Args & {
|
||||
export type PostgresAdapter = BaseDatabaseAdapter & {
|
||||
drizzle: DrizzleDB
|
||||
enums: Record<string, GenericEnum>
|
||||
pool: Pool
|
||||
poolOptions: Args['pool']
|
||||
relations: Record<string, GenericRelation>
|
||||
schema: Record<string, GenericEnum | GenericRelation | GenericTable>
|
||||
sessions: {
|
||||
@@ -60,7 +59,7 @@ export type PostgresAdapter = BaseDatabaseAdapter &
|
||||
}
|
||||
}
|
||||
tables: Record<string, GenericTable>
|
||||
}
|
||||
}
|
||||
|
||||
export type PostgresAdapterResult = (args: { payload: Payload }) => PostgresAdapter
|
||||
|
||||
@@ -68,7 +67,7 @@ export type MigrateUpArgs = { payload: Payload }
|
||||
export type MigrateDownArgs = { payload: Payload }
|
||||
|
||||
declare module 'payload' {
|
||||
export interface DatabaseAdapter extends Args {
|
||||
export interface DatabaseAdapter extends Omit<Args, 'pool'> {
|
||||
drizzle: DrizzleDB
|
||||
enums: Record<string, GenericEnum>
|
||||
pool: Pool
|
||||
|
||||
@@ -21,10 +21,10 @@ const databaseAdapters = {
|
||||
url: 'mongodb://127.0.0.1/payloadtests',
|
||||
}),
|
||||
postgres: postgresAdapter({
|
||||
client: {
|
||||
migrationDir: path.resolve(__dirname, '../packages/db-postgres/migrations'),
|
||||
pool: {
|
||||
connectionString: process.env.POSTGRES_URL || 'postgres://127.0.0.1:5432/payloadtests',
|
||||
},
|
||||
migrationDir: path.resolve(__dirname, '../packages/db-postgres/migrations'),
|
||||
}),
|
||||
}
|
||||
|
||||
@@ -33,11 +33,11 @@ export function buildConfigWithDefaults(testConfig?: Partial<Config>): Promise<S
|
||||
|
||||
const config: Config = {
|
||||
editor: slateEditor({}),
|
||||
telemetry: false,
|
||||
rateLimit: {
|
||||
window: 15 * 60 * 100, // 15min default,
|
||||
max: 9999999999,
|
||||
window: 15 * 60 * 100, // 15min default,
|
||||
},
|
||||
telemetry: false,
|
||||
...testConfig,
|
||||
db: databaseAdapters[process.env.PAYLOAD_DATABASE || 'mongoose'],
|
||||
}
|
||||
@@ -60,6 +60,8 @@ export function buildConfigWithDefaults(testConfig?: Partial<Config>): Promise<S
|
||||
: webpackConfig
|
||||
return {
|
||||
...existingConfig,
|
||||
name,
|
||||
cache: process.env.NODE_ENV === 'test' ? { type: 'memory' } : existingConfig.cache,
|
||||
entry: {
|
||||
main: [
|
||||
`webpack-hot-middleware/client?path=${
|
||||
@@ -68,27 +70,25 @@ export function buildConfigWithDefaults(testConfig?: Partial<Config>): Promise<S
|
||||
path.resolve(__dirname, '../packages/payload/src/admin'),
|
||||
],
|
||||
},
|
||||
name,
|
||||
cache: process.env.NODE_ENV === 'test' ? { type: 'memory' } : existingConfig.cache,
|
||||
resolve: {
|
||||
...existingConfig.resolve,
|
||||
alias: {
|
||||
...existingConfig.resolve?.alias,
|
||||
[path.resolve(__dirname, '../packages/db-postgres/src/index')]: path.resolve(
|
||||
[path.resolve(__dirname, '../packages/bundler-vite/src/index')]: path.resolve(
|
||||
__dirname,
|
||||
'../packages/db-postgres/mock.js',
|
||||
),
|
||||
[path.resolve(__dirname, '../packages/db-mongodb/src/index')]: path.resolve(
|
||||
__dirname,
|
||||
'../packages/db-mongodb/mock.js',
|
||||
'../packages/bundler-vite/mock.js',
|
||||
),
|
||||
[path.resolve(__dirname, '../packages/bundler-webpack/src/index')]: path.resolve(
|
||||
__dirname,
|
||||
'../packages/bundler-webpack/src/mocks/emptyModule.js',
|
||||
),
|
||||
[path.resolve(__dirname, '../packages/bundler-vite/src/index')]: path.resolve(
|
||||
[path.resolve(__dirname, '../packages/db-mongodb/src/index')]: path.resolve(
|
||||
__dirname,
|
||||
'../packages/bundler-vite/mock.js',
|
||||
'../packages/db-mongodb/mock.js',
|
||||
),
|
||||
[path.resolve(__dirname, '../packages/db-postgres/src/index')]: path.resolve(
|
||||
__dirname,
|
||||
'../packages/db-postgres/mock.js',
|
||||
),
|
||||
react: path.resolve(__dirname, '../packages/payload/node_modules/react'),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user