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