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

--- Tcp router --- (8, 8)
INSERT INTO object_type (_id, name, descr) VALUES (8, 'tcp', 'TCP router');
INSERT INTO object(_id, _otype, guid, name, descr, revision, uri, status) VALUES (8, 8, 'tcp', 'TCP router server', 'TCP router server default', 0, '', 0);
INSERT INTO object_connection(_omaster, _oslave, type) VALUES (0, 8, 0);
INSERT INTO object(_id, _otype, guid, name, descr, revision, uri, status) VALUES (16, 8, 'tc_', 'TCP router client', 'TCP router client default', 0, '', 0);
INSERT INTO object_connection(_omaster, _oslave, type) VALUES (0, 16, 0);

--- Tcp router --- (8, 8)
INSERT INTO object_settings_type(_otype, key, name, descr, type, min_value, max_value)
  VALUES (8, 'Type', 'Server', 'Type of router', 'bool', 'client', 'server');
INSERT INTO object_settings_type(_otype, key, name, descr, type, min_value, max_value)
  VALUES (8, 'Port', 'Port', 'Server port', 'int', '1024', '65535');
INSERT INTO object_settings_type(_otype, key, name, descr, type, min_value, max_value)
  VALUES (8, 'Host', 'Host', 'Server host name or IP address', 'text', '', '');
INSERT INTO object_settings_type(_otype, key, name, descr, type, min_value, max_value)
  VALUES (8, 'HostPort', 'Host port', 'Server host port', 'int', '1024', '65535');
INSERT INTO object_settings(_object, key, value) VALUES (8, 'Server', '1');
INSERT INTO object_settings(_object, key, value) VALUES (8, 'Port', '10000');
INSERT INTO object_settings(_object, key, value) VALUES (16, 'Server', '0');
INSERT INTO object_settings(_object, key, value) VALUES (16, 'Host', '92.53.102.118');
INSERT INTO object_settings(_object, key, value) VALUES (16, 'HostPort', '10000');
INSERT INTO object_settings(_object, key, value) VALUES (16, 'Port', '22');

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