Skip to content

Commit

Permalink
feat: add dynamic postgres adapter selection
Browse files Browse the repository at this point in the history
  • Loading branch information
maneike committed Nov 7, 2024
1 parent c16405c commit 6d447de
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,24 @@ export const preparePayloadConfig = async (configPath: PathLike) => {

// Replace postgresAdapter with vercelPostgresAdapter
const oldImport = `import { postgresAdapter } from '@payloadcms/db-postgres'`;
const newImport = `import { vercelPostgresAdapter as postgresAdapter } from '@payloadcms/db-vercel-postgres'`;
const newImport = `import { postgresAdapter } from '@payloadcms/db-postgres'; import { vercelPostgresAdapter as postgresAdapter } from '@payloadcms/db-vercel-postgres';`;

data = data.replace(oldImport, newImport);

// Update the db configuration
const dbConfig = `db: postgresAdapter({
schemaName: "payload",
pool: {
connectionString: process.env.POSTGRES_URL || process.env.DATABASE_URI || "",
},
})`;
const dbConfig = `db: process.env.POSTGRES_URL
? vercelPostgresAdapter({
schemaName: "payload",
pool: {
connectionString: process.env.POSTGRES_URL || "",
},
})
: postgresAdapter({
schemaName: "payload",
pool: {
connectionString: process.env.DATABASE_URI || "",
},
}),`;

data = data.replace(
/db:\s*postgresAdapter\(\{[\s\S]*?pool:\s*\{[\s\S]*?connectionString:[\s\S]*?\}[\s\S]*?\}\)/m,
Expand Down

0 comments on commit 6d447de

Please sign in to comment.