Browse Source

Merge pull request #5633 from thingsboard/lwm2m_script_ctrategy_bootstrap

[3.3.3] lwm2m - script from 3.3.2 to 3.3.3 add to profile bootstrapServerUpdateEnabl…
pull/5661/head
Yevhen Bondarenko 5 years ago
committed by GitHub
parent
commit
d5c3b679a2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 99
      application/src/main/data/upgrade/3.3.2/schema_update_lwm2m_bootstrap.sql

99
application/src/main/data/upgrade/3.3.2/schema_update_lwm2m_bootstrap.sql

@ -20,15 +20,15 @@ $$
BEGIN BEGIN
UPDATE device_profile UPDATE device_profile
SET profile_data = jsonb_set( SET profile_data = jsonb_set(
profile_data, profile_data,
'{transportConfiguration, bootstrap}', '{transportConfiguration}',
get_bootstrap( get_bootstrap(
profile_data::jsonb #> '{transportConfiguration,bootstrap}', profile_data::jsonb #> '{transportConfiguration}',
subquery.publickey_bs, subquery.publickey_bs,
subquery.publickey_lw), subquery.publickey_lw),
true) true)
FROM ( FROM (
SELECT id, SELECT id,
encode( encode(
@ -40,47 +40,58 @@ SET profile_data = jsonb_set(
FROM device_profile FROM device_profile
WHERE transport_type = 'LWM2M' WHERE transport_type = 'LWM2M'
) AS subquery ) AS subquery
WHERE device_profile.id = subquery.id WHERE device_profile.id = subquery.id
AND subquery.publickey_bs IS NOT NULL AND subquery.publickey_bs IS NOT NULL
AND subquery.publickey_lw IS NOT NULL; AND subquery.publickey_lw IS NOT NULL;
END; END;
$$; $$;
CREATE OR REPLACE FUNCTION get_bootstrap(bootstrap_in jsonb, publickey_bs text, publickey_lw text) RETURNS jsonb AS CREATE OR REPLACE FUNCTION get_bootstrap(transport_configuration_in jsonb, publickey_bs text,
publickey_lw text) RETURNS jsonb AS
$$ $$
BEGIN
RETURN json_build_array( DECLARE
json_build_object('shortServerId', bootstrap_in::json #> '{bootstrapServer}' -> 'serverId', bootstrap_new jsonb;
'securityMode', bootstrap_in::json #> '{bootstrapServer}' ->> 'securityMode', bootstrap_in jsonb;
'binding', bootstrap_in::json #> '{servers}' ->> 'binding',
'lifetime', bootstrap_in::json #> '{servers}' -> 'lifetime', BEGIN
'notifIfDisabled', bootstrap_in::json #> '{servers}' -> 'notifIfDisabled', bootstrap_in := transport_configuration_in::jsonb #> '{bootstrap}';
'defaultMinPeriod', bootstrap_in::json #> '{servers}' -> 'defaultMinPeriod', bootstrap_new := json_build_array(
'host', bootstrap_in::json #> '{bootstrapServer}' ->> 'host', json_build_object('shortServerId', bootstrap_in::json #> '{bootstrapServer}' -> 'serverId',
'port', bootstrap_in::json #> '{bootstrapServer}' -> 'port', 'securityMode', bootstrap_in::json #> '{bootstrapServer}' ->> 'securityMode',
'serverPublicKey', publickey_bs, 'binding', bootstrap_in::json #> '{servers}' ->> 'binding',
'bootstrapServerIs', true, 'lifetime', bootstrap_in::json #> '{servers}' -> 'lifetime',
'clientHoldOffTime', bootstrap_in::json #> '{bootstrapServer}' -> 'clientHoldOffTime', 'notifIfDisabled', bootstrap_in::json #> '{servers}' -> 'notifIfDisabled',
'bootstrapServerAccountTimeout', 'defaultMinPeriod', bootstrap_in::json #> '{servers}' -> 'defaultMinPeriod',
bootstrap_in::json #> '{bootstrapServer}' -> 'bootstrapServerAccountTimeout' 'host', bootstrap_in::json #> '{bootstrapServer}' ->> 'host',
), 'port', bootstrap_in::json #> '{bootstrapServer}' -> 'port',
json_build_object('shortServerId', bootstrap_in::json #> '{lwm2mServer}' -> 'serverId', 'serverPublicKey', publickey_bs,
'securityMode', bootstrap_in::json #> '{lwm2mServer}' ->> 'securityMode', 'bootstrapServerIs', true,
'binding', bootstrap_in::json #> '{servers}' ->> 'binding', 'clientHoldOffTime', bootstrap_in::json #> '{bootstrapServer}' -> 'clientHoldOffTime',
'lifetime', bootstrap_in::json #> '{servers}' -> 'lifetime', 'bootstrapServerAccountTimeout',
'notifIfDisabled', bootstrap_in::json #> '{servers}' -> 'notifIfDisabled', bootstrap_in::json #> '{bootstrapServer}' -> 'bootstrapServerAccountTimeout'
'defaultMinPeriod', bootstrap_in::json #> '{servers}' -> 'defaultMinPeriod', ),
'host', bootstrap_in::json #> '{lwm2mServer}' ->> 'host', json_build_object('shortServerId', bootstrap_in::json #> '{lwm2mServer}' -> 'serverId',
'port', bootstrap_in::json #> '{lwm2mServer}' -> 'port', 'securityMode', bootstrap_in::json #> '{lwm2mServer}' ->> 'securityMode',
'serverPublicKey', publickey_lw, 'binding', bootstrap_in::json #> '{servers}' ->> 'binding',
'bootstrapServerIs', false, 'lifetime', bootstrap_in::json #> '{servers}' -> 'lifetime',
'clientHoldOffTime', bootstrap_in::json #> '{lwm2mServer}' -> 'clientHoldOffTime', 'notifIfDisabled', bootstrap_in::json #> '{servers}' -> 'notifIfDisabled',
'bootstrapServerAccountTimeout', 'defaultMinPeriod', bootstrap_in::json #> '{servers}' -> 'defaultMinPeriod',
bootstrap_in::json #> '{lwm2mServer}' -> 'bootstrapServerAccountTimeout' 'host', bootstrap_in::json #> '{lwm2mServer}' ->> 'host',
) 'port', bootstrap_in::json #> '{lwm2mServer}' -> 'port',
); 'serverPublicKey', publickey_lw,
'bootstrapServerIs', false,
'clientHoldOffTime', bootstrap_in::json #> '{lwm2mServer}' -> 'clientHoldOffTime',
'bootstrapServerAccountTimeout',
bootstrap_in::json #> '{lwm2mServer}' -> 'bootstrapServerAccountTimeout'
)
);
RETURN jsonb_set(
transport_configuration_in,
'{bootstrap}',
bootstrap_new,
true) || '{"bootstrapServerUpdateEnable": true}';
END ; END ;
$$ LANGUAGE plpgsql; $$ LANGUAGE plpgsql;

Loading…
Cancel
Save