Files
geo/api/migration_add_departements_contours.sql
Pierre 0687900564 fix: Récupérer l'opération active depuis la table operations
- Corrige l'erreur SQL 'Unknown column fk_operation in users'
- L'opération active est récupérée depuis operations.chk_active = 1
- Jointure avec users pour filtrer par entité de l'admin créateur
- Query: SELECT o.id FROM operations o INNER JOIN users u ON u.fk_entite = o.fk_entite WHERE u.id = ? AND o.chk_active = 1
2026-01-26 16:57:08 +01:00

28 lines
1.8 KiB
SQL
Executable File

-- Table pour stocker les contours (polygones) des départements
CREATE TABLE IF NOT EXISTS `x_departements_contours` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`code_dept` varchar(3) NOT NULL COMMENT 'Code département (22, 2A, 971...)',
`nom_dept` varchar(100) NOT NULL,
`contour` POLYGON NOT NULL COMMENT 'Polygone du contour du département',
`bbox_min_lat` decimal(10,8) DEFAULT NULL COMMENT 'Latitude min de la bounding box',
`bbox_max_lat` decimal(10,8) DEFAULT NULL COMMENT 'Latitude max de la bounding box',
`bbox_min_lng` decimal(11,8) DEFAULT NULL COMMENT 'Longitude min de la bounding box',
`bbox_max_lng` decimal(11,8) DEFAULT NULL COMMENT 'Longitude max de la bounding box',
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `idx_code_dept` (`code_dept`),
SPATIAL KEY `idx_contour` (`contour`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Index pour améliorer les performances
CREATE INDEX idx_dept_bbox ON x_departements_contours (bbox_min_lat, bbox_max_lat, bbox_min_lng, bbox_max_lng);
-- Exemples d'insertion (à remplacer par les vraies données)
-- Les coordonnées doivent être dans l'ordre : longitude latitude
-- Le polygone doit être fermé (premier point = dernier point)
/*
INSERT INTO x_departements_contours (code_dept, nom_dept, contour, bbox_min_lat, bbox_max_lat, bbox_min_lng, bbox_max_lng) VALUES
('22', 'Côtes-d\'Armor', ST_GeomFromText('POLYGON((-3.65 48.90, -2.00 48.90, -2.00 48.05, -3.65 48.05, -3.65 48.90))'), 48.05, 48.90, -3.65, -2.00),
('29', 'Finistère', ST_GeomFromText('POLYGON((-5.14 48.75, -3.38 48.75, -3.38 47.64, -5.14 47.64, -5.14 48.75))'), 47.64, 48.75, -5.14, -3.38);
*/