-- Protecao de ronda por geolocalizacao:
-- - checkpoint com coordenada + raio permitido (geofence)
-- - scan salva localizacao exata do colaborador

SET NAMES utf8mb4;
USE `ponto-sas`;

ALTER TABLE `patrol_checkpoints`
  ADD COLUMN `latitude` DECIMAL(10,7) NULL AFTER `point_name`,
  ADD COLUMN `longitude` DECIMAL(10,7) NULL AFTER `latitude`,
  ADD COLUMN `radius_m` INT UNSIGNED NOT NULL DEFAULT 80 AFTER `longitude`;

ALTER TABLE `patrol_scans`
  ADD COLUMN `scan_latitude` DECIMAL(10,7) NULL AFTER `raw_qr_text`,
  ADD COLUMN `scan_longitude` DECIMAL(10,7) NULL AFTER `scan_latitude`,
  ADD COLUMN `scan_accuracy_m` DECIMAL(8,2) NULL AFTER `scan_longitude`,
  ADD COLUMN `distance_to_checkpoint_m` DECIMAL(8,2) NULL AFTER `scan_accuracy_m`;

-- Ordem sugerida de migrations: 10, 11, 12, 13.
