feat: set up development database and test cleanup utilities

This commit is contained in:
2026-03-31 16:52:56 -07:00
parent 48a96ce65f
commit 26c5158724
6 changed files with 389 additions and 23 deletions
+27
View File
@@ -51,6 +51,22 @@ function createDatabase() {
}
}
function dropDatabase() {
try {
const dbUrl = process.env.DATABASE_URL;
const dbName = dbUrl.split('/').pop();
// Drop existing connections and database
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' });
execSync(`psql "${dbUrl}" -c "DROP DATABASE IF EXISTS ${dbName};" 2>/dev/null || true`, { stdio: 'pipe' });
console.log(`✅ Database "${dbName}" dropped`);
return true;
} catch (error) {
console.error('❌ Failed to drop database:', error.message);
return false;
}
}
function runMigrations() {
try {
console.log('🔄 Running migrations...');
@@ -76,6 +92,9 @@ function generatePrismaClient() {
}
function main() {
const args = process.argv.slice(2);
const shouldDrop = args.includes('--drop');
console.log('=== PostgreSQL Setup for EuchreCamp ===\n');
// Check if DATABASE_URL is set
@@ -90,6 +109,14 @@ function main() {
process.exit(1);
}
// Drop database if requested
if (shouldDrop) {
console.log('Dropping existing database...');
if (!dropDatabase()) {
process.exit(1);
}
}
// Create database
if (!createDatabase()) {
process.exit(1);