const { Client } = require('pg');

async function inspect() {
    const client = new Client({
        host: '87.106.21.21',
        port: 5432,
        user: 'enwelo_admin',
        password: 'WX1t1cgP1qK09',
        database: 'enwelo'
    });
    
    try {
        await client.connect();
        const tables = [
            'geodaten.flaecheneigentuemer_alkis',
            'geodaten.flaecheneigentuemer_alkis_zuweisung',
            'geodaten.flaecheneigentuemer_status'
        ];

        for (const table of tables) {
            const [schema, name] = table.split('.');
            console.log(`\n--- Structure of ${table} ---`);
            const res = await client.query(`
                SELECT column_name, data_type, is_nullable
                FROM information_schema.columns
                WHERE table_schema = $1 AND table_name = $2
                ORDER BY ordinal_position;
            `, [schema, name]);
            res.rows.forEach(r => console.log(`${r.column_name}: ${r.data_type} (${r.is_nullable})`));
        }

        console.log(`\n--- Views in geodaten ---`);
        const viewsRes = await client.query(`
            SELECT table_name 
            FROM information_schema.views 
            WHERE table_schema = 'geodaten';
        `);
        viewsRes.rows.forEach(r => console.log(r.table_name));

    } catch (e) {
        console.error("Error:", e);
    } finally {
        await client.end();
    }
}
inspect();
