FINAL FIX: Switch to pure lowercase SQL without quotes; keeping frontend aliases
Deploy TrassenPlaner / deploy (push) Waiting to run Details

This commit is contained in:
Johannes Baumeister 2026-04-20 09:16:07 +02:00
parent 1197919173
commit 6489f42e42
1 changed files with 47 additions and 47 deletions

View File

@ -29,7 +29,7 @@ app.use(express.static(__dirname));
// Helper to run the schema isolation command
async function setSchema(client) {
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
@ -46,21 +46,21 @@ app.get('/api/owners', async (req, res) => {
try {
await setSchema(client);
// Using exact quoted names to preserve case-sensitivity
// Pure lowercase SQL without quotes on identifiers, using aliases for frontend
const query = `
SELECT
"id",
"Nachname",
"Vorname",
"Ort",
"Flur",
"Flurstueck",
"Gemarkung",
"status" as "status",
"notiz" as "notiz",
"Str_HNr",
ST_AsGeoJSON(ST_Transform("geom", 4326)) as geometry
FROM "eigentuemerdaten"
select
id,
nachname as "Nachname",
vorname as "Vorname",
ort as "Ort",
flur as "Flur",
flurstueck as "Flurstueck",
gemarkung as "Gemarkung",
status,
notiz,
str_hnr as "Str_HNr",
st_asgeojson(st_transform(geom, 4326)) as geometry
from eigentuemerdaten
`;
const result = await client.query(query);
@ -91,11 +91,11 @@ app.get('/api/usage', async (req, res) => {
try {
await setSchema(client);
const query = `
SELECT
"id",
"nutzart" as "nutzart",
ST_AsGeoJSON(ST_Transform("geom", 4326)) as geometry
FROM "nutzung"
select
id,
nutzart,
st_asgeojson(st_transform(geom, 4326)) as geometry
from nutzung
`;
const result = await client.query(query);
@ -125,11 +125,11 @@ app.get('/api/wea', async (req, res) => {
try {
await setSchema(client);
const query = `
SELECT
"id",
"Name",
ST_AsGeoJSON(ST_Transform("geom", 4326)) as geometry
FROM "wea"
select
id,
name as "Name",
st_asgeojson(st_transform(geom, 4326)) as geometry
from wea
`;
const result = await client.query(query);
@ -158,10 +158,10 @@ app.get('/api/infrastructure', async (req, res) => {
try {
await setSchema(client);
const query = `
SELECT
"id",
ST_AsGeoJSON(ST_Transform("geom", 4326)) as geometry
FROM "infrastruktur"
select
id,
st_asgeojson(st_transform(geom, 4326)) as geometry
from infrastruktur
`;
const result = await client.query(query);
@ -190,11 +190,11 @@ app.get('/api/variants', async (req, res) => {
try {
await setSchema(client);
const query = `
SELECT
"id", "name", "Variante",
ST_AsGeoJSON(ST_Transform(ST_SetSRID("geom", 25832), 4326)) as geometry
FROM "kabeltrasse"
ORDER BY "id" DESC
select
id, name, variante as "Variante",
st_asgeojson(st_transform(st_setsrid(geom, 25832), 4326)) as geometry
from kabeltrasse
order by id desc
`;
const result = await client.query(query);
@ -233,19 +233,19 @@ app.post('/api/variants', async (req, res) => {
const varianteValue = properties.Variante || (properties.name ? properties.name.replace('Variante ', '') : 'A');
const geoJsonStr = JSON.stringify(geometry);
// Using exact quoted column names for the UPSERT
// Save with pure lowercase identifiers
const upsertQuery = `
INSERT INTO "kabeltrasse" ("geom", "name", "Variante")
VALUES (
ST_MakeValid(ST_Transform(ST_SetSRID(ST_GeomFromGeoJSON($1), 4326), 25832)),
insert into kabeltrasse (geom, name, variante)
values (
st_makevalid(st_transform(st_setsrid(st_geomfromgeojson($1), 4326), 25832)),
$2,
$3
)
ON CONFLICT ("Variante")
DO UPDATE SET
"geom" = EXCLUDED."geom",
"name" = EXCLUDED."name"
RETURNING "id"
on conflict (variante)
do update set
geom = excluded.geom,
name = excluded.name
returning id
`;
const upsertRes = await client.query(upsertQuery, [geoJsonStr, routeName, varianteValue]);
@ -266,10 +266,10 @@ app.patch('/api/owners/:id', async (req, res) => {
try {
await setSchema(client);
const query = `
UPDATE "eigentuemerdaten"
SET "status" = $1, "notiz" = $2
WHERE "id" = $3
RETURNING "id";
update eigentuemerdaten
set status = $1, notiz = $2
where id = $3
returning id;
`;
const result = await client.query(query, [status, notiz, id]);
if (result.rowCount === 0) return res.status(404).json({ error: 'Owner not found' });