-- Insert all sensors for analytics
INSERT INTO analytics.sensors (unit_id, sensor_id)
SELECT u.unit_id, s.sensor_id FROM export.sensors AS s
JOIN export.units_to_sensors AS us ON us.sensor_id = s.sensor_id
JOIN export.units AS u ON u.unit_id = us.unit_id;


-- Create groups for all registered sensors
INSERT INTO analytics.groups_interval(id, name, time_interval, persistence, collector_type)
SELECT id, CONCAT(unit_id, '/', sensor_id), 3600, true, 'DOUBLE' FROM analytics.sensors;

-- Map every sensor to its group (1:1 relation)
INSERT INTO analytics.sensor_to_group(sensor_id, group_id)
SELECT id, id FROM analytics.groups_interval;

