DO $$
DECLARE
 version_new_ CONSTANT integer := 18;-- new version number --
 ver_ integer;
BEGIN
  LOCK TABLE variables;
  SELECT version_is('Ls') INTO ver_;
  IF ver_ < version_new_ THEN
    -- begin update --

INSERT INTO object_settings_type(_otype, key, name, descr, type, min_value, max_value)
                         VALUES (3, 'DlMissMax', 'DL max miss', 'Maximum misses for downlink, before stop retriing', 'int', '0', '30');

PERFORM objects_add_setting(3, 'DlMissMax', '3');

UPDATE object_settings_type
 SET type='time_period', min_value='0', max_value='240000'
 WHERE _otype=3 AND key='DeviceBusy';

ALTER TABLE downlink ADD COLUMN miss integer DEFAULT 0;

    -- end update --
    PERFORM version_set('Ls', version_new_);
  END IF;
END$$;