require('dotenv').config({ path: require('node:path').join(__dirname, '../.env') });
const { Client } = require('pg');

async function check() {
    const host = process.env.DB_HOST;
    const port = Number(process.env.DB_PORT || 5432);
    const user = process.env.DB_USER;
    const password = process.env.DB_PASSWORD;
    const database = process.env.DB_NAME;

    if (!host || !password) {
        console.error("Missing database environment configuration (DB_HOST, DB_PASSWORD). Please check your .env file.");
        return;
    }

    const client = new Client({
        host,
        port,
        user,
        password,
        database
    });
    
    try {
        await client.connect();
        const res = await client.query(`
            SELECT table_schema, table_name 
            FROM information_schema.views 
            WHERE table_name ILIKE '%wea%';
        `);
        console.log("Views with 'wea' in their name:");
        res.rows.forEach(r => console.log(`${r.table_schema}.${r.table_name}`));
    } catch (e) {
        console.error("Error:", e);
    } finally {
        await client.end();
    }
}
check();
