FINAL SCHEMA MATCH: Quoted mixed-case columns for QGIS compatibility
Deploy TrassenPlaner / deploy (push) Waiting to run Details

This commit is contained in:
Johannes Baumeister 2026-04-20 09:19:19 +02:00
parent 6489f42e42
commit 7753c8b262
1 changed files with 44 additions and 43 deletions

View File

@ -29,7 +29,7 @@ app.use(express.static(__dirname));
// Helper to run the schema isolation command // Helper to run the schema isolation command
async function setSchema(client) { async function setSchema(client) {
const schema = process.env.DB_SCHEMA || 'wind_projekt_bwscheddebrock'; const schema = process.env.DB_SCHEMA || 'wind_projekt_bwscheddebrock';
await client.query(`set search_path to ${schema}, public;`); await client.query(`SET search_path TO "${schema}", public;`);
} }
// Database Initial Setup / Migration Logic Removed // Database Initial Setup / Migration Logic Removed
@ -46,21 +46,23 @@ app.get('/api/owners', async (req, res) => {
try { try {
await setSchema(client); await setSchema(client);
// Pure lowercase SQL without quotes on identifiers, using aliases for frontend // Strict Case-Sensitivity Mapping based on server structure
const query = ` const query = `
select SELECT
id, id,
nachname as "Nachname", nachname AS "Nachname",
vorname as "Vorname", vorname AS "Vorname",
ort as "Ort", ort AS "Ort",
flur as "Flur", "Flur" AS "Flur",
flurstueck as "Flurstueck", "FlSt" AS "Flurstueck",
gemarkung as "Gemarkung", "Gema" AS "Gemarkung",
status, "PLZ" AS "PLZ",
notiz, "Land" AS "Land",
str_hnr as "Str_HNr", "AFlaeche" AS "AFlaeche",
st_asgeojson(st_transform(geom, 4326)) as geometry status as "status",
from eigentuemerdaten notiz as "notiz",
ST_AsGeoJSON(ST_Transform(geom, 4326)) as geometry
FROM eigentuemerdaten
`; `;
const result = await client.query(query); const result = await client.query(query);
@ -91,11 +93,11 @@ app.get('/api/usage', async (req, res) => {
try { try {
await setSchema(client); await setSchema(client);
const query = ` const query = `
select SELECT
id, id,
nutzart, "nutzart" as "nutzart",
st_asgeojson(st_transform(geom, 4326)) as geometry ST_AsGeoJSON(ST_Transform(geom, 4326)) as geometry
from nutzung FROM nutzung
`; `;
const result = await client.query(query); const result = await client.query(query);
@ -125,11 +127,11 @@ app.get('/api/wea', async (req, res) => {
try { try {
await setSchema(client); await setSchema(client);
const query = ` const query = `
select SELECT
id, id,
name as "Name", "Name" AS "Name",
st_asgeojson(st_transform(geom, 4326)) as geometry ST_AsGeoJSON(ST_Transform(geom, 4326)) as geometry
from wea FROM wea
`; `;
const result = await client.query(query); const result = await client.query(query);
@ -158,10 +160,10 @@ app.get('/api/infrastructure', async (req, res) => {
try { try {
await setSchema(client); await setSchema(client);
const query = ` const query = `
select SELECT
id, id,
st_asgeojson(st_transform(geom, 4326)) as geometry ST_AsGeoJSON(ST_Transform(geom, 4326)) as geometry
from infrastruktur FROM infrastruktur
`; `;
const result = await client.query(query); const result = await client.query(query);
@ -190,11 +192,11 @@ app.get('/api/variants', async (req, res) => {
try { try {
await setSchema(client); await setSchema(client);
const query = ` const query = `
select SELECT
id, name, variante as "Variante", id, name, "Variante" AS "Variante",
st_asgeojson(st_transform(st_setsrid(geom, 25832), 4326)) as geometry ST_AsGeoJSON(ST_Transform(ST_SetSRID(geom, 25832), 4326)) as geometry
from kabeltrasse FROM kabeltrasse
order by id desc ORDER BY id DESC
`; `;
const result = await client.query(query); const result = await client.query(query);
@ -233,19 +235,18 @@ app.post('/api/variants', async (req, res) => {
const varianteValue = properties.Variante || (properties.name ? properties.name.replace('Variante ', '') : 'A'); const varianteValue = properties.Variante || (properties.name ? properties.name.replace('Variante ', '') : 'A');
const geoJsonStr = JSON.stringify(geometry); const geoJsonStr = JSON.stringify(geometry);
// Save with pure lowercase identifiers
const upsertQuery = ` const upsertQuery = `
insert into kabeltrasse (geom, name, variante) INSERT INTO kabeltrasse (geom, name, "Variante")
values ( VALUES (
st_makevalid(st_transform(st_setsrid(st_geomfromgeojson($1), 4326), 25832)), ST_MakeValid(ST_Transform(ST_SetSRID(ST_GeomFromGeoJSON($1), 4326), 25832)),
$2, $2,
$3 $3
) )
on conflict (variante) ON CONFLICT ("Variante")
do update set DO UPDATE SET
geom = excluded.geom, geom = EXCLUDED.geom,
name = excluded.name name = EXCLUDED.name
returning id RETURNING id
`; `;
const upsertRes = await client.query(upsertQuery, [geoJsonStr, routeName, varianteValue]); const upsertRes = await client.query(upsertQuery, [geoJsonStr, routeName, varianteValue]);
@ -266,10 +267,10 @@ app.patch('/api/owners/:id', async (req, res) => {
try { try {
await setSchema(client); await setSchema(client);
const query = ` const query = `
update eigentuemerdaten UPDATE eigentuemerdaten
set status = $1, notiz = $2 SET status = $1, notiz = $2
where id = $3 WHERE id = $3
returning id; RETURNING id;
`; `;
const result = await client.query(query, [status, notiz, id]); const result = await client.query(query, [status, notiz, id]);
if (result.rowCount === 0) return res.status(404).json({ error: 'Owner not found' }); if (result.rowCount === 0) return res.status(404).json({ error: 'Owner not found' });