From 3ef8e1d01796a098022c78cae33bb3ecbea0ca9a Mon Sep 17 00:00:00 2001 From: Johannes Baumeister Date: Tue, 12 May 2026 13:15:24 +0200 Subject: [PATCH] Mirror Nordex geometries and add version marker v1.0.2 --- backend/check_new_alkis.js | 31 ++++++++++++++++++++++++ backend/check_old_alkis.js | 27 +++++++++++++++++++++ backend/check_wea.js | 23 ++++++++++++++++++ backend/fix_db.js | 34 +++++++++++++++++++++++++++ backend/fix_view.js | 48 ++++++++++++++++++++++++++++++++++++++ backend/test_resolution.js | 24 +++++++++++++++++++ enwelo_db.session.sql | 0 index.html | 2 +- 8 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 backend/check_new_alkis.js create mode 100644 backend/check_old_alkis.js create mode 100644 backend/check_wea.js create mode 100644 backend/fix_db.js create mode 100644 backend/fix_view.js create mode 100644 backend/test_resolution.js create mode 100644 enwelo_db.session.sql diff --git a/backend/check_new_alkis.js b/backend/check_new_alkis.js new file mode 100644 index 0000000..5223ec5 --- /dev/null +++ b/backend/check_new_alkis.js @@ -0,0 +1,31 @@ +const { Client } = require('pg'); + +async function check() { + const client = new Client({ + host: '87.106.21.21', + port: 5432, + user: 'enwelo_admin', + password: 'WX1t1cgP1qK09', + database: 'enwelo' + }); + + try { + await client.connect(); + const res = await client.query(` + SELECT column_name, data_type + FROM information_schema.columns + WHERE table_schema = 'geodaten' AND table_name = 'flaecheneigentuemer_alkis' + `); + console.log("Columns in geodaten.flaecheneigentuemer_alkis:"); + console.log(res.rows); + + const sample = await client.query('SELECT * FROM geodaten.flaecheneigentuemer_alkis LIMIT 1'); + console.log("\nSample row:"); + console.log(sample.rows[0]); + } catch (e) { + console.error(e); + } finally { + await client.end(); + } +} +check(); diff --git a/backend/check_old_alkis.js b/backend/check_old_alkis.js new file mode 100644 index 0000000..449ccea --- /dev/null +++ b/backend/check_old_alkis.js @@ -0,0 +1,27 @@ +const { Client } = require('pg'); + +async function check() { + const client = new Client({ + host: '87.106.21.21', + port: 5432, + user: 'enwelo_admin', + password: 'WX1t1cgP1qK09', + database: 'enwelo' + }); + + try { + await client.connect(); + const res = await client.query(` + SELECT column_name, data_type + FROM information_schema.columns + WHERE table_schema = 'geodaten' AND table_name = 'flaecheneigentuemer_alkis2' + `); + console.log("Columns in geodaten.flaecheneigentuemer_alkis2:"); + console.log(res.rows.map(r => r.column_name).join(', ')); + } catch (e) { + console.error(e); + } finally { + await client.end(); + } +} +check(); diff --git a/backend/check_wea.js b/backend/check_wea.js new file mode 100644 index 0000000..10c8719 --- /dev/null +++ b/backend/check_wea.js @@ -0,0 +1,23 @@ +const { Client } = require('pg'); + +async function check() { + const client = new Client({ + host: '87.106.21.21', + port: 5432, + user: 'enwelo_admin', + password: 'WX1t1cgP1qK09', + database: 'enwelo' + }); + + try { + await client.connect(); + const res = await client.query("SELECT column_name, data_type FROM information_schema.columns WHERE table_schema = 'geodaten' AND table_name = 'wea_standorte'"); + console.log("Columns in geodaten.wea_standorte:"); + console.log(res.rows); + } catch (e) { + console.error(e); + } finally { + await client.end(); + } +} +check(); diff --git a/backend/fix_db.js b/backend/fix_db.js new file mode 100644 index 0000000..0a87438 --- /dev/null +++ b/backend/fix_db.js @@ -0,0 +1,34 @@ +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(); diff --git a/backend/fix_view.js b/backend/fix_view.js new file mode 100644 index 0000000..099a2dc --- /dev/null +++ b/backend/fix_view.js @@ -0,0 +1,48 @@ +const { Client } = require('pg'); + +async function fixView() { + const client = new Client({ + host: '87.106.21.21', + port: 5432, + user: 'enwelo_admin', + password: 'WX1t1cgP1qK09', + database: 'enwelo' + }); + + try { + await client.connect(); + + const createViewSql = ` +CREATE OR REPLACE VIEW geodaten.v_projekt_sicherung AS +SELECT az.projekt_id, + p.name AS projekt_name, + a.id AS alkis_id, + a."FSK" AS fsk, + a."GNA" AS nachname, + a."VNA" AS vorname, + a.bemerkung AS nof_zusatz, + COALESCE(s.status, 'Unbekannt'::text) AS aktueller_status, + s.datum AS status_datum, + r.farbe_hex, + a.geom + FROM geodaten.flaecheneigentuemer_alkis_zuweisung az + JOIN geodaten.flaecheneigentuemer_alkis a ON az.fsk = a."FSK" + JOIN geodaten.projekte p ON az.projekt_id = p.id + LEFT JOIN LATERAL ( SELECT flaecheneigentuemer_status.status, + flaecheneigentuemer_status.datum + FROM geodaten.flaecheneigentuemer_status + WHERE flaecheneigentuemer_status.fsk = az.fsk AND flaecheneigentuemer_status.projekt_id = az.projekt_id + ORDER BY flaecheneigentuemer_status.datum DESC + LIMIT 1) s ON true + LEFT JOIN geodaten.ref_sicherungsstatus r ON s.status = r.status_name; + `; + + await client.query(createViewSql); + console.log("View recreated successfully."); + } catch (e) { + console.error(e); + } finally { + await client.end(); + } +} +fixView(); diff --git a/backend/test_resolution.js b/backend/test_resolution.js new file mode 100644 index 0000000..f8a5027 --- /dev/null +++ b/backend/test_resolution.js @@ -0,0 +1,24 @@ +const { Client } = require('pg'); +const client = new Client({ host: '87.106.21.21', port: 5432, user: 'enwelo_admin', password: 'WX1t1cgP1qK09', database: 'enwelo' }); + +async function resolveProjectId(client, input) { + if (!input) return null; + const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; + if (uuidRegex.test(input)) return input; + const normalized = input.toLowerCase().replace(/[-_]/g, ''); + const res = await client.query('SELECT id FROM geodaten.projekte WHERE LOWER(REPLACE(REPLACE(name, \'-\', \'\'), \'_\', \'\')) = $1', [normalized]); + return res.rows.length > 0 ? res.rows[0].id : null; +} + +client.connect().then(async () => { + try { + const pid = await resolveProjectId(client, 'BWSamern-Ohne'); + console.log('Resolved PID:', pid); + const res = await client.query('SELECT vorname, nachname, aktueller_status as status FROM geodaten.v_projekt_sicherung WHERE projekt_id = $1 LIMIT 5', [pid]); + console.table(res.rows); + } catch (e) { + console.error(e); + } finally { + client.end(); + } +}); diff --git a/enwelo_db.session.sql b/enwelo_db.session.sql new file mode 100644 index 0000000..e69de29 diff --git a/index.html b/index.html index f0aac6a..286f517 100644 --- a/index.html +++ b/index.html @@ -142,7 +142,7 @@
- Bereit. + Bereit. (v1.0.2 - Mirrored Nordex)