From 93849353e5c31dadfaa772fdff0317e79d642915 Mon Sep 17 00:00:00 2001 From: 0xWulf Date: Tue, 8 Jul 2025 09:44:57 +0900 Subject: [PATCH] Remove example DB connection scripts and document env variable --- .env.example | 1 + server/test-db.js | 86 ------------------------------------------- test_db_connection.js | 34 ----------------- test_db_lowercase.js | 46 ----------------------- 4 files changed, 1 insertion(+), 166 deletions(-) delete mode 100644 server/test-db.js delete mode 100644 test_db_connection.js delete mode 100644 test_db_lowercase.js diff --git a/.env.example b/.env.example index 6da83b5..921c359 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,7 @@ # Port Configuration PORT=3001 # PostgreSQL Configuration +# Replace with the connection string for your database DATABASE_URL=postgresql://username:password@localhost:5432/codepatchwork PGDATABASE=codepatchwork PGUSER=username diff --git a/server/test-db.js b/server/test-db.js deleted file mode 100644 index 29e911e..0000000 --- a/server/test-db.js +++ /dev/null @@ -1,86 +0,0 @@ -import 'dotenv/config'; -import pg from 'pg'; -const { Pool } = pg; - -const connectionString = process.env.DATABASE_URL || 'postgresql://codepatchwork_user:1S1HwpTVdmilD8tNeGmI@localhost:5432/codepatchwork'; -console.log("Using connection string:", connectionString.replace(/:[^:]*@/, ':***@')); // Hide password in logs - -const pool = new Pool({ connectionString }); - -async function testDatabase() { - console.log("Testing database connection..."); - let client; - - try { - client = await pool.connect(); - console.log("✅ Successfully connected to database!"); - - // Basic query test - const timeResult = await client.query('SELECT NOW() as time'); - console.log("✅ Database time:", timeResult.rows[0].time); - - // List tables - const tablesResult = await client.query(` - SELECT table_name - FROM information_schema.tables - WHERE table_schema = 'public' - `); - - console.log("\nTables in database:"); - if (tablesResult.rows.length === 0) { - console.log("❌ No tables found in public schema!"); - } else { - tablesResult.rows.forEach(row => { - console.log(`- ${row.table_name}`); - }); - } - - // Try queries on specific tables - try { - const snippetsResult = await client.query('SELECT COUNT(*) FROM snippets'); - console.log(`✅ Found ${snippetsResult.rows[0].count} records in snippets table`); - } catch (e) { - console.log(`❌ Error querying snippets table: ${e.message}`); - } - - try { - const tagsResult = await client.query('SELECT COUNT(*) FROM tags'); - console.log(`✅ Found ${tagsResult.rows[0].count} records in tags table`); - } catch (e) { - console.log(`❌ Error querying tags table: ${e.message}`); - } - - try { - const collectionsResult = await client.query('SELECT COUNT(*) FROM collections'); - console.log(`✅ Found ${collectionsResult.rows[0].count} records in collections table`); - } catch (e) { - console.log(`❌ Error querying collections table: ${e.message}`); - } - - // Check users table - try { - const usersResult = await client.query('SELECT COUNT(*) FROM users'); - console.log(`✅ Found ${usersResult.rows[0].count} records in users table`); - - if (usersResult.rows[0].count > 0) { - // Check column types for the first user - const userColumns = await client.query('SELECT * FROM users LIMIT 1'); - console.log("\nUser table structure:"); - Object.entries(userColumns.rows[0]).forEach(([key, value]) => { - console.log(`- ${key}: ${typeof value} (${value === null ? 'null' : value})`); - }); - } - } catch (e) { - console.log(`❌ Error querying users table: ${e.message}`); - } - - } catch (connectionError) { - console.error("❌ Failed to connect to database:", connectionError); - } finally { - if (client) client.release(); - await pool.end(); - } -} - -// Run the test -testDatabase(); diff --git a/test_db_connection.js b/test_db_connection.js deleted file mode 100644 index 831ca57..0000000 --- a/test_db_connection.js +++ /dev/null @@ -1,34 +0,0 @@ -const { Pool } = require('pg'); - -// Use the same connection string as your application -const pool = new Pool({ - connectionString: 'postgresql://codepatchwork_user:1S1HwpTVdmilD8tNeGmI@localhost:5432/codepatchwork' -}); - -async function testConnection() { - try { - // Test basic connection - const client = await pool.connect(); - console.log('Successfully connected to the database'); - - // Test querying the snippets table - const snippetsResult = await client.query('SELECT COUNT(*) FROM snippets'); - console.log('Snippets count:', snippetsResult.rows[0].count); - - // Test querying the tags table - const tagsResult = await client.query('SELECT COUNT(*) FROM tags'); - console.log('Tags count:', tagsResult.rows[0].count); - - // Test querying the collections table - const collectionsResult = await client.query('SELECT COUNT(*) FROM collections'); - console.log('Collections count:', collectionsResult.rows[0].count); - - client.release(); - } catch (error) { - console.error('Database connection error:', error); - } finally { - pool.end(); - } -} - -testConnection(); diff --git a/test_db_lowercase.js b/test_db_lowercase.js deleted file mode 100644 index a2dd4d9..0000000 --- a/test_db_lowercase.js +++ /dev/null @@ -1,46 +0,0 @@ -// Direct database test with lowercase column names -import pg from 'pg'; -const { Pool } = pg; - -const pool = new Pool({ - connectionString: 'postgres://codepatchwork_user:1S1HwpTVdmilD8tNeGmI@localhost:5432/codepatchwork' -}); - -async function testLowercaseQueries() { - const client = await pool.connect(); - try { - console.log('Connected to database successfully'); - - // Test snippets table with lowercase column names - console.log('Testing snippets table:'); - const snippetsResult = await client.query('SELECT COUNT(*) FROM snippets'); - console.log(`- Found ${snippetsResult.rows[0].count} snippets`); - - const snippetsSample = await client.query('SELECT id, title, language, userid, createdat, updatedat FROM snippets LIMIT 3'); - console.log('- Sample snippets:', JSON.stringify(snippetsSample.rows, null, 2)); - - // Test collectionItems table - console.log('\nTesting collectionItems table:'); - try { - const collectionItemsResult = await client.query('SELECT COUNT(*) FROM "collectionItems"'); - console.log(`- Found ${collectionItemsResult.rows[0].count} collection items`); - - const columnInfo = await client.query(` - SELECT column_name, data_type - FROM information_schema.columns - WHERE table_name = 'collectionItems' - `); - console.log('- Column information:', columnInfo.rows); - } catch (err) { - console.error('- Error testing collectionItems:', err.message); - } - - } catch (err) { - console.error('Database test error:', err); - } finally { - client.release(); - await pool.end(); - } -} - -testLowercaseQueries();