feat(db-postgres): configurable custom schema to use (#5047)
* feat(db-postgres): configurable custom schema to use * test(db-postgres): use public schema * chore(db-postgres): simplify drop schema * chore: add postgres-custom-schema test to ci * chore: add custom schema to postgres ci * chore(db-postgres): custom schema in migrate * chore: ci postgres wait condition
This commit is contained in:
@@ -35,6 +35,13 @@ const databaseAdapters = {
|
||||
connectionString: process.env.POSTGRES_URL || 'postgres://127.0.0.1:5432/payloadtests',
|
||||
},
|
||||
}),
|
||||
'postgres-custom-schema': postgresAdapter({
|
||||
migrationDir,
|
||||
pool: {
|
||||
connectionString: process.env.POSTGRES_URL || 'postgres://127.0.0.1:5432/payloadtests',
|
||||
},
|
||||
schemaName: 'custom',
|
||||
}),
|
||||
'postgres-uuid': postgresAdapter({
|
||||
idType: 'uuid',
|
||||
migrationDir,
|
||||
|
||||
@@ -3,7 +3,7 @@ import fs from 'fs'
|
||||
import { GraphQLClient } from 'graphql-request'
|
||||
import path from 'path'
|
||||
|
||||
import type { DrizzleDB } from '../../packages/db-postgres/src/types'
|
||||
import type { PostgresAdapter } from '../../packages/db-postgres/src/types'
|
||||
import type { TypeWithID } from '../../packages/payload/src/collections/config/types'
|
||||
import type { PayloadRequest } from '../../packages/payload/src/express/types'
|
||||
|
||||
@@ -44,10 +44,14 @@ describe('database', () => {
|
||||
describe('migrations', () => {
|
||||
beforeAll(async () => {
|
||||
if (process.env.PAYLOAD_DROP_DATABASE === 'true' && 'drizzle' in payload.db) {
|
||||
const drizzle = payload.db.drizzle as DrizzleDB
|
||||
// @ts-expect-error drizzle raw sql typing
|
||||
await drizzle.execute(sql`drop schema public cascade;
|
||||
create schema public;`)
|
||||
const db = payload.db as unknown as PostgresAdapter
|
||||
const drizzle = db.drizzle
|
||||
const schemaName = db.schemaName || 'public'
|
||||
|
||||
await drizzle.execute(
|
||||
sql.raw(`drop schema ${schemaName} cascade;
|
||||
create schema ${schemaName};`),
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ export async function resetDB(_payload: Payload, collectionSlugs: string[]) {
|
||||
return
|
||||
}
|
||||
const queries = Object.values(schema).map((table: any) => {
|
||||
return sql.raw(`DELETE FROM ${table.dbName}`)
|
||||
return sql.raw(`DELETE FROM ${db.schemaName ? db.schemaName + '.' : ''}${table.dbName}`)
|
||||
})
|
||||
|
||||
await db.drizzle.transaction(async (trx) => {
|
||||
|
||||
Reference in New Issue
Block a user