Emergency fix: Prevention of accidental data loss during sync
Deploy TrassenPlaner / deploy (push) Waiting to run
Details
Deploy TrassenPlaner / deploy (push) Waiting to run
Details
This commit is contained in:
parent
1185a5b5e0
commit
6c6eb92dbb
|
|
@ -2731,10 +2731,12 @@
|
||||||
const indicator = document.getElementById('db-status-indicator');
|
const indicator = document.getElementById('db-status-indicator');
|
||||||
if (indicator) indicator.classList.add('active');
|
if (indicator) indicator.classList.add('active');
|
||||||
|
|
||||||
|
try {
|
||||||
try {
|
try {
|
||||||
// Ensure we have a valid variant object and points
|
// Ensure we have a valid variant object and points
|
||||||
const v = variantDef.id ? variantDef : state.variants.find(vx => vx.id === variantDef.id);
|
if (!variantDef.id && !variantDef.name) return;
|
||||||
if (!v) {
|
const v = variantDef.id ? variantDef : state.variants.find(vx => vx.id === variantDef.id || vx.name === variantDef.name);
|
||||||
|
if (!v || !v.routes || v.routes.length < 2) {
|
||||||
if (indicator) indicator.classList.remove('active');
|
if (indicator) indicator.classList.remove('active');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
43
server.js
43
server.js
|
|
@ -226,22 +226,37 @@ app.post('/api/variants', async (req, res) => {
|
||||||
const routeName = properties.name || 'Neue Trasse';
|
const routeName = properties.name || 'Neue Trasse';
|
||||||
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);
|
||||||
|
|
||||||
|
// Safety Check: DON'T delete/save if geometry is empty or invalid
|
||||||
|
if (!geometry || !geometry.coordinates || geometry.coordinates.length < 2) {
|
||||||
|
console.log(`Aborting save for ${varianteValue}: Geometry is too short or empty.`);
|
||||||
|
return res.json({ success: true, message: 'Skipped empty geometry' });
|
||||||
|
}
|
||||||
|
|
||||||
// Delete existing variant if it exists (Manual UPSERT to bypass missing index permissions)
|
try {
|
||||||
await client.query('DELETE FROM kabeltrasse WHERE "Variante" = $1 OR name = $2', [varianteValue, routeName]);
|
await client.query('BEGIN');
|
||||||
|
|
||||||
|
// Delete existing variant if it exists
|
||||||
|
await client.query('DELETE FROM kabeltrasse WHERE "Variante" = $1 OR name = $2', [varianteValue, routeName]);
|
||||||
|
|
||||||
const insertQuery = `
|
const insertQuery = `
|
||||||
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_Multi(ST_MakeValid(ST_Transform(ST_SetSRID(ST_GeomFromGeoJSON($1), 4326), 25832))),
|
||||||
$2,
|
$2,
|
||||||
$3
|
$3
|
||||||
)
|
)
|
||||||
RETURNING id
|
RETURNING id
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const insertRes = await client.query(insertQuery, [geoJsonStr, routeName, varianteValue]);
|
const insertRes = await client.query(insertQuery, [geoJsonStr, routeName, varianteValue]);
|
||||||
res.json({ success: true, id: insertRes.rows[0].id });
|
await client.query('COMMIT');
|
||||||
|
|
||||||
|
res.json({ success: true, id: insertRes.rows[0].id });
|
||||||
|
} catch (sqlErr) {
|
||||||
|
await client.query('ROLLBACK');
|
||||||
|
throw sqlErr;
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("SQL-FEHLER (SAVE):", err.message);
|
console.error("SQL-FEHLER (SAVE):", err.message);
|
||||||
res.status(500).json({ error: 'Failed to save variant' });
|
res.status(500).json({ error: 'Failed to save variant' });
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue