fix(roads): replace ON CONFLICT with delete and insert for bulletproof candidate approval
This commit is contained in:
@@ -227,19 +227,15 @@ export class RoadRefinementController {
|
|||||||
CREATE UNIQUE INDEX IF NOT EXISTS approved_roads_cand_uidx ON approved_roads(candidate_id) WHERE candidate_id IS NOT NULL;
|
CREATE UNIQUE INDEX IF NOT EXISTS approved_roads_cand_uidx ON approved_roads(candidate_id) WHERE candidate_id IS NOT NULL;
|
||||||
`);
|
`);
|
||||||
|
|
||||||
// 2. Direct insert/upsert into approved_roads immediately
|
// 2. Direct insert into approved_roads immediately (Delete existing first to ensure idempotency)
|
||||||
await this.dataSource.query(`
|
await this.dataSource.query(`
|
||||||
|
DELETE FROM approved_roads WHERE candidate_id = $1::uuid;
|
||||||
INSERT INTO approved_roads (
|
INSERT INTO approved_roads (
|
||||||
candidate_id, geometry, name, highway, confidence, "uniqueDriverCount", oneway, approved_at
|
candidate_id, geometry, name, highway, confidence, "uniqueDriverCount", oneway, approved_at
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
id, geometry::geometry, COALESCE(name, 'Unnamed Road'), COALESCE(highway, 'residential'), confidence, "uniqueDriverCount", COALESCE(oneway, 0), NOW()
|
id, geometry::geometry, COALESCE(name, 'Unnamed Road'), COALESCE(highway, 'residential'), confidence, "uniqueDriverCount", COALESCE(oneway, 0), NOW()
|
||||||
FROM candidate_roads WHERE id = $1
|
FROM candidate_roads WHERE id = $1::uuid;
|
||||||
ON CONFLICT (candidate_id) DO UPDATE SET
|
|
||||||
geometry = EXCLUDED.geometry,
|
|
||||||
name = EXCLUDED.name,
|
|
||||||
highway = EXCLUDED.highway,
|
|
||||||
confidence = EXCLUDED.confidence;
|
|
||||||
`, [id]);
|
`, [id]);
|
||||||
|
|
||||||
// 3. Mark candidate as approved
|
// 3. Mark candidate as approved
|
||||||
|
|||||||
Reference in New Issue
Block a user