45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
|
|
import { Pool } from 'pg';
|
||
|
|
import * as dotenv from 'dotenv';
|
||
|
|
import * as path from 'path';
|
||
|
|
|
||
|
|
// Load .env.local first (takes precedence), then .env
|
||
|
|
dotenv.config({ path: path.resolve(process.cwd(), '.env.local') });
|
||
|
|
dotenv.config({ path: path.resolve(process.cwd(), '.env') });
|
||
|
|
|
||
|
|
const pool = new Pool({
|
||
|
|
connectionString: process.env.DATABASE_URL,
|
||
|
|
});
|
||
|
|
|
||
|
|
async function listTables() {
|
||
|
|
try {
|
||
|
|
console.log('Connecting to database...');
|
||
|
|
console.log('DATABASE_URL:', process.env.DATABASE_URL?.replace(/:[^:@]+@/, ':****@'));
|
||
|
|
|
||
|
|
// List all tables
|
||
|
|
const result = await pool.query(`
|
||
|
|
SELECT table_name
|
||
|
|
FROM information_schema.tables
|
||
|
|
WHERE table_schema = 'public'
|
||
|
|
ORDER BY table_name;
|
||
|
|
`);
|
||
|
|
|
||
|
|
console.log('\n=== Tables in Database ===');
|
||
|
|
if (result.rows.length === 0) {
|
||
|
|
console.log('No tables found!');
|
||
|
|
} else {
|
||
|
|
result.rows.forEach((row) => {
|
||
|
|
console.log(`- ${row.table_name}`);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
console.log(`\nTotal: ${result.rows.length} tables`);
|
||
|
|
|
||
|
|
} catch (error) {
|
||
|
|
console.error('Error listing tables:', error);
|
||
|
|
} finally {
|
||
|
|
await pool.end();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
listTables();
|