feat: add database test safety configuration
This commit is contained in:
@@ -7,8 +7,18 @@
|
||||
|
||||
const { execSync } = require('child_process');
|
||||
|
||||
// Database connection string
|
||||
const DB_URL = 'postgresql://euchre_camp:LINGO5row_hiding@dhg.lol:5432/euchre_camp';
|
||||
// Database connection string - use environment variable or default to production
|
||||
const DB_URL = process.env.PROD_DATABASE_URL ||
|
||||
process.env.DATABASE_URL ||
|
||||
'postgresql://euchre_camp:LINGO5row_hiding@dhg.lol:5432/euchre_camp';
|
||||
|
||||
// Validate that we're not accidentally using dev database
|
||||
if (DB_URL.includes('_dev') || DB_URL.includes('_dev_')) {
|
||||
console.error('❌ ERROR: This script should not be used with the development database!');
|
||||
console.error(' Current DATABASE_URL:', DB_URL);
|
||||
console.error(' Please set PROD_DATABASE_URL for production database operations.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Helper to run SQL and log results
|
||||
function runSQL(sql, description) {
|
||||
|
||||
@@ -10,8 +10,18 @@
|
||||
|
||||
const { execSync } = require('child_process');
|
||||
|
||||
// Database connection string
|
||||
const DB_URL = 'postgresql://euchre_camp:LINGO5row_hiding@dhg.lol:5432/euchre_camp';
|
||||
// Database connection string - use environment variable or default to production
|
||||
const DB_URL = process.env.PROD_DATABASE_URL ||
|
||||
process.env.DATABASE_URL ||
|
||||
'postgresql://euchre_camp:LINGO5row_hiding@dhg.lol:5432/euchre_camp';
|
||||
|
||||
// Validate that we're not accidentally using dev database
|
||||
if (DB_URL.includes('_dev') || DB_URL.includes('_dev_')) {
|
||||
console.error('❌ ERROR: This script should not be used with the development database!');
|
||||
console.error(' Current DATABASE_URL:', DB_URL);
|
||||
console.error(' Please set PROD_DATABASE_URL for production database operations.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Helper to run SQL and log results
|
||||
function runSQL(sql, description) {
|
||||
|
||||
+20
-6
@@ -11,21 +11,35 @@ const { execSync } = require('child_process');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// Load environment variables
|
||||
// Load environment variables - prioritize explicit DEV_DATABASE_URL
|
||||
// Falls back to DATABASE_URL, then .env.development
|
||||
const envPath = path.resolve(__dirname, '..', '.env.development');
|
||||
if (fs.existsSync(envPath)) {
|
||||
require('dotenv').config({ path: envPath });
|
||||
}
|
||||
|
||||
// Check if DATABASE_URL is set
|
||||
if (!process.env.DATABASE_URL) {
|
||||
console.error('❌ DATABASE_URL is not set');
|
||||
console.error('Please set it in .env.development');
|
||||
// Use DEV_DATABASE_URL if set, otherwise use DATABASE_URL
|
||||
const databaseUrl = process.env.DEV_DATABASE_URL || process.env.DATABASE_URL;
|
||||
|
||||
// Check if database URL is set
|
||||
if (!databaseUrl) {
|
||||
console.error('❌ No database URL set');
|
||||
console.error('Please set DEV_DATABASE_URL or DATABASE_URL environment variable');
|
||||
console.error('Or ensure .env.development file exists with DATABASE_URL');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Validate that we're using the dev database
|
||||
if (!databaseUrl.includes('_dev') && !databaseUrl.includes('_dev_')) {
|
||||
console.error('❌ ERROR: This script should only be used with the development database!');
|
||||
console.error(' Current URL:', databaseUrl);
|
||||
console.error(' Expected pattern: euchre_camp_dev');
|
||||
console.error(' Please set DEV_DATABASE_URL for development database operations.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Extract database name from URL
|
||||
const dbUrl = process.env.DATABASE_URL;
|
||||
const dbUrl = databaseUrl;
|
||||
const dbName = dbUrl.split('/').pop();
|
||||
|
||||
console.log('🔄 Resetting development database...\n');
|
||||
|
||||
Reference in New Issue
Block a user