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

INSERT INTO station_type (name, descr, endpoint, cpu_arch, os_name, os_version) VALUES ('H', 'x86 v1.0', 'debug', 'x86_64', 'ubuntu', '18\.\d*');
SELECT value FROM variables WHERE _object IS NULL AND key='Cloud' INTO cloud_;
SELECT version() INTO psql_ver_;
IF (cloud_ IS NULL) AND (psql_ver_ LIKE '% on x86_64%') THEN
  UPDATE object_settings SET value = '1'
    WHERE key = 'RabbitSsl';
  UPDATE object_settings SET value = '5671'
    WHERE key = 'RabbitPort';

  WITH uplink_id AS (SELECT _id FROM object WHERE name='Uplink')
  UPDATE object_settings
    SET value = '300000'
  FROM uplink_id
    WHERE key = 'SampleRate' AND uplink_id._id = _object;
END IF;

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