Files
Connect-5/apply-schema.js
DeNNiiInc 0a8ea2b603 Migrate from Supabase to direct PostgreSQL connection
- Replace @supabase/supabase-js with native pg library
- Rewrite database.js to use PostgreSQL connection pool
- Update server.js with PostgreSQL connection testing
- Create postgres-schema.sql with complete database schema
- Add apply-schema.js script for easy schema deployment
- Update all documentation (README.md, DEPLOYMENT.md, deploy.sh)
- Remove Supabase-specific files and references
- Update db.config.example.js with PostgreSQL format
2025-12-22 12:54:36 +11:00

61 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Quick script to apply postgres-schema.sql to the database
// Run with: node apply-schema.js
const fs = require('fs');
const { Pool } = require('pg');
const dbConfig = require('./db.config.js');
const pool = new Pool({
host: dbConfig.HOST,
user: dbConfig.USER,
password: dbConfig.PASSWORD,
database: dbConfig.DB,
port: 5432
});
async function applySchema() {
try {
console.log('📄 Reading postgres-schema.sql...');
const schema = fs.readFileSync('./postgres-schema.sql', 'utf8');
console.log('🔗 Connecting to PostgreSQL...');
console.log(` Host: ${dbConfig.HOST}`);
console.log(` Database: ${dbConfig.DB}`);
console.log('⚙️ Applying schema...');
await pool.query(schema);
console.log('✅ Schema applied successfully!');
// Verify tables were created
console.log('\n🔍 Verifying tables...');
const result = await pool.query(`
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public'
AND table_name IN ('players', 'active_sessions', 'games', 'game_moves')
ORDER BY table_name;
`);
console.log(`✅ Found ${result.rows.length} tables:`);
result.rows.forEach(row => {
console.log(` - ${row.table_name}`);
});
if (result.rows.length === 4) {
console.log('\n🎉 Database setup complete! You can now run: npm start');
} else {
console.log('\n⚠ Warning: Expected 4 tables but found', result.rows.length);
}
} catch (error) {
console.error('❌ Error applying schema:', error.message);
console.error('\nDetails:', error);
process.exit(1);
} finally {
await pool.end();
}
}
applySchema();