From 52b1a9a7208eac59ad2a6137b2e2a8b0bd953d4f Mon Sep 17 00:00:00 2001 From: Patrik Date: Fri, 20 Dec 2024 11:02:06 -0500 Subject: [PATCH] templates: removes `DATABASE_URI` env var from `with-vercel-website` template .env.example (#10098) ### What? Previously, the `with-vercel-website` template included a `DATABASE_URI` env var in the `.env.example` file - which was unneeded. ### Why? The `with-vercel-website` template uses a `POSTGRES_URL` env var for the db connection string env var instead. ### How? Removes the `DATABASE_URI` env var from the .env.example file. Also, updates the `DATABASE_URI` db string names in the following templates from `payloadtests` to `your-database-name` for a more generic / clear name: - with-postgres - with-vercel-mongodb - with-vercel-postgres - with-vercel-website --- scripts/build-template-with-local-pkgs.ts | 2 +- scripts/generate-template-variations.ts | 20 ++++++++++++++++--- templates/with-postgres/.env.example | 2 +- templates/with-vercel-mongodb/.env.example | 2 +- templates/with-vercel-postgres/.env.example | 2 +- templates/with-vercel-website/.env.example | 4 +--- .../with-vercel-website/docker-compose.yml | 2 +- 7 files changed, 23 insertions(+), 11 deletions(-) diff --git a/scripts/build-template-with-local-pkgs.ts b/scripts/build-template-with-local-pkgs.ts index ba6b0e155..ce79fbdca 100644 --- a/scripts/build-template-with-local-pkgs.ts +++ b/scripts/build-template-with-local-pkgs.ts @@ -16,7 +16,7 @@ async function main() { const templateDir = path.resolve(dirname, '../templates') const templateName = process.argv[2] const templatePath = path.join(templateDir, templateName) - const databaseConnection = process.argv[3] || 'mongodb://127.0.0.1/payloadtests' + const databaseConnection = process.argv[3] || 'mongodb://127.0.0.1/your-database-name' console.log({ templatePath, diff --git a/scripts/generate-template-variations.ts b/scripts/generate-template-variations.ts index 8b6d1793e..bba075579 100644 --- a/scripts/generate-template-variations.ts +++ b/scripts/generate-template-variations.ts @@ -251,7 +251,7 @@ async function main() { ...process.env, PAYLOAD_SECRET: 'asecretsolongnotevensantacouldguessit', BLOB_READ_WRITE_TOKEN: 'vercel_blob_rw_TEST_asdf', - DATABASE_URI: process.env.POSTGRES_URL || 'postgres://localhost:5432/payloadtests', + DATABASE_URI: process.env.POSTGRES_URL || 'postgres://localhost:5432/your-database-name', }, }) } @@ -315,12 +315,25 @@ async function writeEnvExample({ const fileContents = envFileContents .split('\n') - .filter((e) => e) + .filter((l) => { + // Remove the unwanted PostgreSQL connection comment for "with-vercel-website" + if ( + dbType === 'vercel-postgres' && + (l.startsWith('# Or use a PG connection string') || + l.startsWith('#DATABASE_URI=postgresql://')) + ) { + return false // Skip this line + } + return true // Keep other lines + }) .map((l) => { if (l.startsWith('DATABASE_URI')) { + if (dbType === 'mongodb') { + l = 'MONGODB_URI=mongodb://127.0.0.1/your-database-name' + } // Use db-appropriate connection string if (dbType.includes('postgres')) { - l = 'DATABASE_URI=postgresql://127.0.0.1:5432/payloadtests' + l = 'DATABASE_URI=postgresql://127.0.0.1:5432/your-database-name' } // Replace DATABASE_URI with the correct env name if set @@ -330,6 +343,7 @@ async function writeEnvExample({ } return l }) + .filter((l) => l.trim() !== '') .join('\n') console.log(`Writing to ${envExamplePath}`) diff --git a/templates/with-postgres/.env.example b/templates/with-postgres/.env.example index c8a4baf92..31dbf0f03 100644 --- a/templates/with-postgres/.env.example +++ b/templates/with-postgres/.env.example @@ -1,2 +1,2 @@ -DATABASE_URI=postgresql://127.0.0.1:5432/payloadtests +DATABASE_URI=postgresql://127.0.0.1:5432/your-database-name PAYLOAD_SECRET=YOUR_SECRET_HERE \ No newline at end of file diff --git a/templates/with-vercel-mongodb/.env.example b/templates/with-vercel-mongodb/.env.example index 22203c5da..d77180b81 100644 --- a/templates/with-vercel-mongodb/.env.example +++ b/templates/with-vercel-mongodb/.env.example @@ -1,2 +1,2 @@ -MONGODB_URI=mongodb://127.0.0.1/payload-template-blank-3-0 +MONGODB_URI=mongodb://127.0.0.1/your-database-name PAYLOAD_SECRET=YOUR_SECRET_HERE \ No newline at end of file diff --git a/templates/with-vercel-postgres/.env.example b/templates/with-vercel-postgres/.env.example index de405df61..74e9e0c52 100644 --- a/templates/with-vercel-postgres/.env.example +++ b/templates/with-vercel-postgres/.env.example @@ -1,2 +1,2 @@ -POSTGRES_URL=postgresql://127.0.0.1:5432/payloadtests +POSTGRES_URL=postgresql://127.0.0.1:5432/your-database-name PAYLOAD_SECRET=YOUR_SECRET_HERE \ No newline at end of file diff --git a/templates/with-vercel-website/.env.example b/templates/with-vercel-website/.env.example index ca43e8c5c..fff6077da 100644 --- a/templates/with-vercel-website/.env.example +++ b/templates/with-vercel-website/.env.example @@ -1,7 +1,5 @@ # Database connection string -POSTGRES_URL=postgresql://127.0.0.1:5432/payloadtests -# Or use a PG connection string -#DATABASE_URI=postgresql://127.0.0.1:5432/payload-template-website +POSTGRES_URL=postgresql://127.0.0.1:5432/your-database-name # Used to encrypt JWT tokens PAYLOAD_SECRET=YOUR_SECRET_HERE # Used to configure CORS, format links and more. No trailing slash diff --git a/templates/with-vercel-website/docker-compose.yml b/templates/with-vercel-website/docker-compose.yml index eac27ce09..0b19cac03 100644 --- a/templates/with-vercel-website/docker-compose.yml +++ b/templates/with-vercel-website/docker-compose.yml @@ -7,7 +7,7 @@ services: - '54320:5432' environment: POSTGRES_USER: postgres - POSTGRES_DB: payloadtests # THIS MUST MATCH YOUR DB NAME IN .env + POSTGRES_DB: your-database-name # THIS MUST MATCH YOUR DB NAME IN .env POSTGRES_HOST_AUTH_METHOD: trust env_file: - .env