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

async function fix() {
    const client = new Client({
        host: '87.106.21.21',
        port: 5432,
        user: 'enwelo_admin',
        password: 'WX1t1cgP1qK09',
        database: 'enwelo'
    });
    
    try {
        await client.connect();
        
        // 1. Rename existing GNA if it exists
        await client.query('ALTER TABLE geodaten.flaecheneigentuemer_alkis RENAME COLUMN "GNA" TO "OLD_GNA"');
        console.log("Renamed GNA to OLD_GNA");

        // 2. Rename NOF to GNA
        await client.query('ALTER TABLE geodaten.flaecheneigentuemer_alkis RENAME COLUMN "NOF" TO "GNA"');
        console.log("Renamed NOF to GNA");

        // 3. Add status and notiz
        await client.query('ALTER TABLE geodaten.flaecheneigentuemer_alkis ADD COLUMN IF NOT EXISTS status text');
        await client.query('ALTER TABLE geodaten.flaecheneigentuemer_alkis ADD COLUMN IF NOT EXISTS notiz text');
        console.log("Added status and notiz columns");
        
    } catch (e) {
        console.error(e);
    } finally {
        await client.end();
    }
}
fix();
