docs: add development database and testing documentation

This commit is contained in:
2026-03-31 16:53:42 -07:00
parent 26c5158724
commit b5af4b2e34
3 changed files with 106 additions and 0 deletions
+40
View File
@@ -161,6 +161,46 @@ DATABASE_URL="postgresql://username:password@localhost:5432/euchre_camp"
DATABASE_SHADOW_URL="postgresql://username:password@localhost:5432/euchre_camp_shadow"
```
## Development Database
For development and testing, use a separate development database to avoid conflicts with production data.
**Setup Development Database:**
```bash
# Create and setup the development database
npm run db:setup-dev
# Reset the development database (drops and recreates)
npm run db:reset-dev
# Clean development database (drop and recreate with migrations)
npm run db:setup-dev:clean
```
**Environment Configuration:**
The development database uses `.env.development` which is automatically configured for:
- Database: `euchre_camp_dev`
- NODE_ENV: `development`
**Testing with Development Database:**
```bash
# Run unit tests (uses test database automatically)
npm run test
# Run acceptance tests (uses development database)
npm run test:acceptance
```
**Test Data Cleanup:**
All tests automatically clean up their created records:
- Global setup/teardown handles Playwright tests
- Test utilities provide `cleanupTestRecords()` for manual cleanup
- Tests use `beforeEach` and `afterEach` hooks for automatic cleanup
## Usage
### Creating a Tournament
+1
View File
@@ -15,6 +15,7 @@
"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:clean": "DATABASE_URL=\"postgresql://euchre_camp:LINGO5row_hiding@dhg.lol:5432/euchre_camp_dev\" node scripts/setup-postgres.js --drop",
"db:reset-dev": "node scripts/reset-dev-db.js",
"db:use-dev": "node scripts/use-dev-db.js",
"db:seed": "node scripts/seed.js",
"docker:up": "docker-compose up -d",
+65
View File
@@ -0,0 +1,65 @@
#!/usr/bin/env node
/**
* Reset Development Database
*
* Drops and recreates the development database with a clean state.
* Useful for development and testing.
*/
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
// Load environment variables
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');
process.exit(1);
}
// Extract database name from URL
const dbUrl = process.env.DATABASE_URL;
const dbName = dbUrl.split('/').pop();
console.log('🔄 Resetting development database...\n');
console.log(`Database: ${dbName}`);
console.log(`URL: ${dbUrl}\n`);
try {
// Drop existing connections
console.log('Dropping existing connections...');
execSync(
`psql "${dbUrl}" -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '${dbName}' AND pid <> pg_backend_pid();" 2>/dev/null || true`,
{ stdio: 'pipe' }
);
// Drop the database
console.log('Dropping database...');
execSync(
`psql "${dbUrl}" -c "DROP DATABASE IF EXISTS ${dbName};" 2>/dev/null || true`,
{ stdio: 'pipe' }
);
// Recreate the database
console.log('Creating database...');
execSync(`psql "${dbUrl}" -c "CREATE DATABASE ${dbName};"`, { stdio: 'pipe' });
// Run migrations
console.log('Running migrations...');
execSync('npx prisma migrate deploy', { stdio: 'inherit' });
console.log('\n✅ Development database reset successfully!');
console.log('\nNext steps:');
console.log('1. Seed the database (optional): npm run db:seed');
console.log('2. Start development server: npm run dev');
} catch (error) {
console.error('\n❌ Failed to reset database:', error.message);
process.exit(1);
}