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

async function fix() {
    require('dotenv').config({ path: '../.env' });
const client = new Client({
    host: process.env.DB_HOST,
    port: process.env.DB_PORT,
    user: process.env.DB_USER,
    password: process.env.DB_PASSWORD,
    database: process.env.DB_NAME
});
    
    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();
