fix: remove hardcoded database URLs and use environment variables
This commit is contained in:
+8
-9
@@ -7,19 +7,18 @@
|
|||||||
"build": "next build",
|
"build": "next build",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
"lint": "eslint",
|
"lint": "eslint",
|
||||||
"test": "DATABASE_URL=\"postgresql://euchre_camp:LINGO5row_hiding@dhg.lol:5432/euchre_camp_dev\" vitest",
|
"test": "vitest",
|
||||||
"test:run": "DATABASE_URL=\"postgresql://euchre_camp:LINGO5row_hiding@dhg.lol:5432/euchre_camp_dev\" vitest run",
|
"test:run": "vitest run",
|
||||||
"test:acceptance": "DATABASE_URL=\"postgresql://euchre_camp:LINGO5row_hiding@dhg.lol:5432/euchre_camp_dev\" playwright test src/__tests__/e2e/",
|
"test:acceptance": "playwright test src/__tests__/e2e/",
|
||||||
"test:acceptance:headed": "DATABASE_URL=\"postgresql://euchre_camp:LINGO5row_hiding@dhg.lol:5432/euchre_camp_dev\" playwright test src/__tests__/e2e/ --headed",
|
"test:acceptance:headed": "playwright test src/__tests__/e2e/ --headed",
|
||||||
"db:switch": "node scripts/switch-database.js",
|
"db:switch": "node scripts/switch-database.js",
|
||||||
"db:setup-postgres": "node scripts/setup-postgres.js",
|
"db:setup-postgres": "node scripts/setup-postgres.js",
|
||||||
"db:setup-dev": "DATABASE_URL=\"postgresql://euchre_camp:LINGO5row_hiding@dhg.lol:5432/euchre_camp_dev\" node scripts/setup-postgres.js",
|
"db:setup-dev": "node scripts/setup-postgres.js",
|
||||||
"db:setup-dev:clean": "DATABASE_URL=\"postgresql://euchre_camp:LINGO5row_hiding@dhg.lol:5432/euchre_camp_dev\" node scripts/setup-postgres.js --drop",
|
"db:setup-dev:clean": "node scripts/setup-postgres.js --drop",
|
||||||
"db:reset-dev": "DEV_DATABASE_URL=\"postgresql://euchre_camp:LINGO5row_hiding@dhg.lol:5432/euchre_camp_dev\" node scripts/reset-dev-db.js",
|
"db:reset-dev": "node scripts/reset-dev-db.js",
|
||||||
"db:use-dev": "node scripts/use-dev-db.js",
|
"db:use-dev": "node scripts/use-dev-db.js",
|
||||||
"db:cleanup-prod": "PROD_DATABASE_URL=\"postgresql://euchre_camp:LINGO5row_hiding@dhg.lol:5432/euchre_camp\" node scripts/cleanup-prod-db.js",
|
|
||||||
"db:check-prod": "PROD_DATABASE_URL=\"postgresql://euchre_camp:LINGO5row_hiding@dhg.lol:5432/euchre_camp\" node scripts/check-test-records.js",
|
|
||||||
"db:cleanup-prod": "node scripts/cleanup-prod-db.js",
|
"db:cleanup-prod": "node scripts/cleanup-prod-db.js",
|
||||||
|
"db:check-prod": "node scripts/check-test-records.js",
|
||||||
"db:seed": "node scripts/seed.js",
|
"db:seed": "node scripts/seed.js",
|
||||||
"docker:up": "docker-compose up -d",
|
"docker:up": "docker-compose up -d",
|
||||||
"docker:down": "docker-compose down",
|
"docker:down": "docker-compose down",
|
||||||
|
|||||||
@@ -7,10 +7,16 @@
|
|||||||
|
|
||||||
const { execSync } = require('child_process');
|
const { execSync } = require('child_process');
|
||||||
|
|
||||||
// Database connection string - use environment variable or default to production
|
// Database connection string - must be explicitly set via environment variable
|
||||||
const DB_URL = process.env.PROD_DATABASE_URL ||
|
const DB_URL = process.env.PROD_DATABASE_URL || process.env.DATABASE_URL;
|
||||||
process.env.DATABASE_URL ||
|
|
||||||
'postgresql://euchre_camp:LINGO5row_hiding@dhg.lol:5432/euchre_camp';
|
// Check if database URL is set
|
||||||
|
if (!DB_URL) {
|
||||||
|
console.error('❌ No database URL set');
|
||||||
|
console.error('Please set PROD_DATABASE_URL or DATABASE_URL environment variable');
|
||||||
|
console.error('For production: PROD_DATABASE_URL="postgresql://user:pass@host:port/dbname"');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
// Validate that we're not accidentally using dev database
|
// Validate that we're not accidentally using dev database
|
||||||
if (DB_URL.includes('_dev') || DB_URL.includes('_dev_')) {
|
if (DB_URL.includes('_dev') || DB_URL.includes('_dev_')) {
|
||||||
|
|||||||
@@ -10,10 +10,16 @@
|
|||||||
|
|
||||||
const { execSync } = require('child_process');
|
const { execSync } = require('child_process');
|
||||||
|
|
||||||
// Database connection string - use environment variable or default to production
|
// Database connection string - must be explicitly set via environment variable
|
||||||
const DB_URL = process.env.PROD_DATABASE_URL ||
|
const DB_URL = process.env.PROD_DATABASE_URL || process.env.DATABASE_URL;
|
||||||
process.env.DATABASE_URL ||
|
|
||||||
'postgresql://euchre_camp:LINGO5row_hiding@dhg.lol:5432/euchre_camp';
|
// Check if database URL is set
|
||||||
|
if (!DB_URL) {
|
||||||
|
console.error('❌ No database URL set');
|
||||||
|
console.error('Please set PROD_DATABASE_URL or DATABASE_URL environment variable');
|
||||||
|
console.error('For production: PROD_DATABASE_URL="postgresql://user:pass@host:port/dbname"');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
// Validate that we're not accidentally using dev database
|
// Validate that we're not accidentally using dev database
|
||||||
if (DB_URL.includes('_dev') || DB_URL.includes('_dev_')) {
|
if (DB_URL.includes('_dev') || DB_URL.includes('_dev_')) {
|
||||||
|
|||||||
@@ -9,8 +9,12 @@ const { execSync } = require('child_process');
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
// Load .env file if it exists
|
// Load .env.development file first (if it exists), then .env file
|
||||||
|
const envDevPath = path.resolve(__dirname, '..', '.env.development');
|
||||||
const envPath = path.resolve(__dirname, '..', '.env');
|
const envPath = path.resolve(__dirname, '..', '.env');
|
||||||
|
if (fs.existsSync(envDevPath)) {
|
||||||
|
require('dotenv').config({ path: envDevPath });
|
||||||
|
}
|
||||||
if (fs.existsSync(envPath)) {
|
if (fs.existsSync(envPath)) {
|
||||||
require('dotenv').config({ path: envPath });
|
require('dotenv').config({ path: envPath });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ if (isProductionDatabase()) {
|
|||||||
console.error('');
|
console.error('');
|
||||||
console.error('To fix this:');
|
console.error('To fix this:');
|
||||||
console.error(' 1. Run: npm run test:acceptance');
|
console.error(' 1. Run: npm run test:acceptance');
|
||||||
console.error(' 2. Or set: DATABASE_URL="postgresql://euchre_camp:password@dhg.lol:5432/euchre_camp_dev"');
|
console.error(' 2. Or set: DATABASE_URL environment variable to dev database URL');
|
||||||
|
console.error(' 3. Or load .env.development: source .env.development && npm run test:acceptance');
|
||||||
console.error('');
|
console.error('');
|
||||||
console.error('Aborting test execution to prevent data corruption.');
|
console.error('Aborting test execution to prevent data corruption.');
|
||||||
console.error('');
|
console.error('');
|
||||||
|
|||||||
+2
-1
@@ -30,7 +30,8 @@ if (databaseUrl) {
|
|||||||
console.error('');
|
console.error('');
|
||||||
console.error('To fix this:');
|
console.error('To fix this:');
|
||||||
console.error(' 1. Run: npm run test:run');
|
console.error(' 1. Run: npm run test:run');
|
||||||
console.error(' 2. Or set: DATABASE_URL="postgresql://euchre_camp:password@dhg.lol:5432/euchre_camp_dev"');
|
console.error(' 2. Or set: DATABASE_URL environment variable to dev database URL');
|
||||||
|
console.error(' 3. Or load .env.development: source .env.development && npm run test:run');
|
||||||
console.error('');
|
console.error('');
|
||||||
console.error('Aborting test execution to prevent data corruption.');
|
console.error('Aborting test execution to prevent data corruption.');
|
||||||
console.error('');
|
console.error('');
|
||||||
|
|||||||
Reference in New Issue
Block a user