-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinspect_schema.js
More file actions
56 lines (48 loc) · 1.47 KB
/
Copy pathinspect_schema.js
File metadata and controls
56 lines (48 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const pg = require('pg');
const { Client } = pg;
const fs = require('fs');
const path = require('path');
const configPath = path.resolve(__dirname, '../supabase-service.json');
if (!fs.existsSync(configPath)) {
console.error('supabase-service.json not found.');
process.exit(1);
}
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
const client = new Client({
host: config.dbHost,
port: config.dbPort || 5432,
user: config.dbUser || 'postgres',
password: config.dbPassword,
database: 'postgres',
ssl: { rejectUnauthorized: false }
});
async function listTables() {
try {
await client.connect();
// List tables in public schema
const res = await client.query(`
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public'
`);
console.log('Tables in public schema:');
for (const row of res.rows) {
console.log(`- ${row.table_name}`);
// Get columns for this table
const cols = await client.query(`
SELECT column_name, data_type, is_nullable
FROM information_schema.columns
WHERE table_schema = 'public' AND table_name = $1
`, [row.table_name]);
console.log(' Columns:');
cols.rows.forEach(c => {
console.log(` ${c.column_name} (${c.data_type}) ${c.is_nullable === 'YES' ? 'NULL' : 'NOT NULL'}`);
});
}
} catch (err) {
console.error('Error listing tables:', err);
} finally {
await client.end();
}
}
listTables();