Commit 45a61abfeb70e0bb5fde42ee1e55833538d9ccdc
Merge branch 'cherry-pick-16c880d0' into 'master'
chore: 更新升级脚本将组态元数据保留并更新 See merge request yunteng/thingskit!268
Showing
1 changed file
with
59 additions
and
0 deletions
... | ... | @@ -261,5 +261,64 @@ return values'); |
261 | 261 | -- ********业务功能升级******** |
262 | 262 | -- **************************** |
263 | 263 | |
264 | +update tk_configuration_center set is_template =0; | |
265 | + | |
266 | +------------------------------------------------ | |
267 | +update tk_configuration_center set product_and_device = a.datajson | |
268 | + from ( | |
269 | +select cent.id as id, | |
270 | +json_agg ( | |
271 | + DISTINCT jsonb_build_object ( | |
272 | + 'profileId', | |
273 | + data.device_profile_id, | |
274 | + 'profileName', | |
275 | + p.name | |
276 | + ) | |
277 | + )as datajson | |
278 | + from tk_configuration_center cent | |
279 | +left JOIN tk_configuration_datasource data on data.configuration_id = cent.id | |
280 | +left join tk_device_profile p on p.id = data.device_profile_id | |
281 | +WHERE data.device_profile_id is not null | |
282 | +GROUP BY cent.id | |
283 | +ORDER BY cent.id)as a | |
284 | +WHERE a.id=tk_configuration_center.id; | |
285 | + | |
286 | +-------------------------------------- | |
287 | + | |
288 | + | |
289 | +update tk_configuration_center set product_and_device = a.actjson | |
290 | + from ( | |
291 | +select id,jsonb_agg(element) as actjson | |
292 | +from | |
293 | +( | |
294 | +select id, jsonb_array_elements (product_and_device::jsonb) as element | |
295 | +from tk_configuration_center | |
296 | + | |
297 | +union | |
298 | + | |
299 | +select act.id, jsonb_array_elements (act.actjson::jsonb) as element | |
300 | +from (select cent.id as id , | |
301 | + json_agg ( | |
302 | + DISTINCT jsonb_build_object ( | |
303 | + 'profileId', | |
304 | + act.device_profile_id, | |
305 | + 'profileName', | |
306 | + p.name | |
307 | + ) | |
308 | + )as actjson | |
309 | + from tk_configuration_center cent | |
310 | +left JOIN tk_configuration_act act on act.configuration_id = cent.id | |
311 | +left join tk_device_profile p on p.id = act.device_profile_id | |
312 | +WHERE act.device_profile_id is not null | |
313 | +GROUP BY cent.id | |
314 | +ORDER BY cent.id) as act | |
315 | + | |
316 | + | |
317 | +)as subquery | |
318 | + | |
319 | +GROUP BY | |
320 | +id | |
321 | +)as a | |
322 | +WHERE a.id=tk_configuration_center.id; | |
264 | 323 | |
265 | 324 | ... | ... |