Standortplaner/db_patch_leitungen.js

35 lines
1.1 KiB
JavaScript

require('dotenv').config({ override: true });
const { Pool } = require('pg');
const pool = new Pool({
host: process.env.DB_HOST,
port: process.env.DB_PORT,
database: process.env.DB_NAME,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD
});
async function run() {
const bwId = '5bb4e049-85f2-4433-b38e-6a66b81e9f06';
try {
console.log('Adding projekt_id to leitungsverleaufe and Freileitungen...');
await pool.query('ALTER TABLE geodaten.leitungsverleaufe ADD COLUMN IF NOT EXISTS projekt_id character varying;');
await pool.query('ALTER TABLE geodaten."Freileitungen" ADD COLUMN IF NOT EXISTS projekt_id character varying;');
const res1 = await pool.query('UPDATE geodaten.leitungsverleaufe SET projekt_id = $1 WHERE projekt_id IS NULL;', [bwId]);
console.log(`Updated ${res1.rowCount} rows in leitungsverleaufe.`);
const res2 = await pool.query('UPDATE geodaten."Freileitungen" SET projekt_id = $1 WHERE projekt_id IS NULL;', [bwId]);
console.log(`Updated ${res2.rowCount} rows in Freileitungen.`);
} catch (err) {
console.error('Error:', err);
} finally {
await pool.end();
}
}
run();