aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ri/src/main/resources/changelog/db/changes/16-insert-cm-handle-state-forward.sql
blob: 01d441f46080bd842b1ba85ce97507393f46a851 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
INSERT INTO
	fragment(
		xpath,
		attributes,
		anchor_id,
		parent_id,
		dataspace_id,
		schema_node_id
	)
SELECT
	concat(cmHandles.xpath, '/state') AS xpath,
	to_jsonb(
		concat(
			'{"cm-handle-state": "READY", "last-update-time": "',
			to_char(
				now(),
				'YYYY-MM-DD"T"HH24:MI:SS.MSTZHTZM'
			),
			'", "data-sync-enabled": false}'
		) :: json
	) AS attributes,
	cmHandles.anchor_id,
	cmHandles.id,
	cmHandles.dataspace_id,
	cmHandles.schema_node_id
FROM
	(
		SELECT
			id,
			xpath,
			anchor_id,
			dataspace_id,
			schema_node_id
		FROM
			fragment
		WHERE
			xpath ~* '^/dmi-registry/cm-handles\[@id=''[\w\-]+''\]$'
			AND xpath NOT IN (
				SELECT
					SUBSTRING(
						xpath
						FROM
							'^/dmi-registry/cm-handles\[@id=''[\w\-]+''\]'
					)
				FROM
					fragment
				WHERE
					xpath ~* '^/dmi-registry/cm-handles\[@id=''[\w\-]+''\]/state$'
			)
	) AS cmHandles;
INSERT INTO
	fragment(
		xpath,
		attributes,
		anchor_id,
		parent_id,
		dataspace_id,
		schema_node_id
	)
SELECT
	concat(cmHandlesStates.xpath, '/datastores'),
	to_jsonb('{}' :: json),
	cmHandlesStates.anchor_id,
	cmHandlesStates.id,
	cmHandlesStates.dataspace_id,
	cmHandlesStates.schema_node_id
FROM
	(
		SELECT
			id,
			xpath,
			anchor_id,
			dataspace_id,
			schema_node_id
		FROM
			fragment
		WHERE
			xpath ~* '^/dmi-registry/cm-handles\[@id=''[\w\-]+''\]/state$'
			AND xpath NOT IN (
				SELECT
					SUBSTRING(
						xpath
						FROM
							'^/dmi-registry/cm-handles\[@id=''[\w\-]+''\]/state'
					)
				FROM
					fragment
				WHERE
					xpath ~* '^/dmi-registry/cm-handles\[@id=''[\w\-]+''\]/state/datastores$'
			)
	) AS cmHandlesStates;
INSERT INTO
	fragment(
		xpath,
		attributes,
		anchor_id,
		parent_id,
		dataspace_id,
		schema_node_id
	)
SELECT
	concat(
		cmHandlesDatastores.xpath,
		'/operational'
	),
	to_jsonb(
		concat('{"sync-state": "NONE_REQUESTED"}') :: json
	),
	cmHandlesDatastores.anchor_id,
	cmHandlesDatastores.id,
	cmHandlesDatastores.dataspace_id,
	cmHandlesDatastores.schema_node_id
FROM
	(
		SELECT
			id,
			xpath,
			anchor_id,
			dataspace_id,
			schema_node_id
		FROM
			fragment
		WHERE
			xpath ~* '^/dmi-registry/cm-handles\[@id=''[\w\-]+''\]/state/datastores$'
			AND xpath NOT IN (
				SELECT
					SUBSTRING(
						xpath
						FROM
							'^/dmi-registry/cm-handles\[@id=''[\w\-]+''\]/state/datastores'
					)
				FROM
					fragment
				WHERE
					xpath ~* '^/dmi-registry/cm-handles\[@id=''[\w\-]+''\]/state/datastores/operational$'
			)
	) AS cmHandlesDatastores;