INSERT INTO property_set (state)
SELECT 'VALID'
WHERE NOT EXISTS (
    SELECT 1 FROM property_set ps
    WHERE ps.state = 'VALID'
      AND ps.start_date <= NOW()
      AND (ps.end_date IS NULL OR ps.end_date > NOW())
);


INSERT INTO validity_period (state)
SELECT 'VALID'
WHERE NOT EXISTS (
    SELECT 1 FROM validity_period vp
    WHERE vp.state = 'VALID'
      AND vp.start_date <= NOW()
      AND (vp.end_date IS NULL OR vp.end_date > NOW())
);