1
|
-ALTER TABLE "public"."user" ADD COLUMN "parent_id" int8 DEFAULT 0;
|
|
|
2
|
-COMMENT ON COLUMN "public"."user"."parent_id" IS '上级ID'; |
|
|
|
|
1
|
+-- 变更user表字段
|
|
|
2
|
+ALTER TABLE "public"."user"
|
|
|
3
|
+ ADD COLUMN "parent_id" int8 DEFAULT 0;
|
|
|
4
|
+
|
|
|
5
|
+COMMENT ON COLUMN "public"."user"."parent_id" IS '上级ID';
|
|
|
6
|
+
|
|
|
7
|
+-- 抽取旧数据到evaluation_item_used
|
|
|
8
|
+WITH t1 AS (
|
|
|
9
|
+ SELECT
|
|
|
10
|
+ evaluation_project.company_id,
|
|
|
11
|
+ evaluation_project.id AS project_id,
|
|
|
12
|
+ jsonb_array_elements(evaluation_project."template" #> '{linkNodes}') AS nodes
|
|
|
13
|
+ FROM
|
|
|
14
|
+ evaluation_project
|
|
|
15
|
+ ORDER BY
|
|
|
16
|
+ id
|
|
|
17
|
+),
|
|
|
18
|
+t2 AS (
|
|
|
19
|
+ SELECT
|
|
|
20
|
+ t1.company_id,
|
|
|
21
|
+ t1.project_id,
|
|
|
22
|
+ t1.nodes ->> 'id' AS node_id,
|
|
|
23
|
+ t1.nodes ->> 'type' AS node_type,
|
|
|
24
|
+ jsonb_array_elements(t1.nodes #> '{nodeContents}') AS node_contents
|
|
|
25
|
+ FROM
|
|
|
26
|
+ t1)
|
|
|
27
|
+ INSERT INTO public.evaluation_item_used (company_id, evaluation_project_id, node_id, node_type, sort_by, category, "name", prompt_title, prompt_text, entry_items, rule_type, "rule", weight, required, created_at, updated_at, evaluator_id)
|
|
|
28
|
+ SELECT
|
|
|
29
|
+ t2.company_id,
|
|
|
30
|
+ t2.project_id,
|
|
|
31
|
+ cast(t2.node_id AS int8) AS node_id,
|
|
|
32
|
+ cast(t2.node_type AS int8) AS node_type,
|
|
|
33
|
+ 0,
|
|
|
34
|
+ t2.node_contents ->> 'category' AS "category",
|
|
|
35
|
+ t2.node_contents ->> 'name' AS "name",
|
|
|
36
|
+ t2.node_contents ->> 'promptTitle' AS "prompt_title",
|
|
|
37
|
+ t2.node_contents ->> 'promptText' AS "prompt_text",
|
|
|
38
|
+ t2.node_contents -> 'entryItems' AS "entry_items",
|
|
|
39
|
+ cast(t2.node_contents #>> '{rule,type}' AS int8) AS rule_type,
|
|
|
40
|
+ t2.node_contents -> 'rule' AS "rule",
|
|
|
41
|
+ cast(t2.node_contents ->> 'weight' AS decimal) AS "weight",
|
|
|
42
|
+ cast(t2.node_contents ->> 'required' AS int8) AS "required",
|
|
|
43
|
+ now(),
|
|
|
44
|
+ now(),
|
|
|
45
|
+ cast(t2.node_contents ->> 'evaluatorId' AS int8) AS "evaluator_id"
|
|
|
46
|
+FROM
|
|
|
47
|
+ t2;
|
|
|
48
|
+
|
|
|
49
|
+-- evaluation_item_used 初始赋值 sort_by
|
|
|
50
|
+UPDATE
|
|
|
51
|
+ evaluation_item_used
|
|
|
52
|
+SET
|
|
|
53
|
+ sort_by = evaluation_item_used.id;
|
|
|
54
|
+
|
|
|
55
|
+-- evaluation_item_used 修正required 的值
|
|
|
56
|
+UPDATE
|
|
|
57
|
+ evaluation_item_used
|
|
|
58
|
+SET
|
|
|
59
|
+ required = 1
|
|
|
60
|
+WHERE
|
|
|
61
|
+ required = 0
|
|
|
62
|
+ OR required ISNULL;
|
|
|
63
|
+
|
|
|
64
|
+-- evaluation_item_used修正weight的 值
|
|
|
65
|
+UPDATE
|
|
|
66
|
+ evaluation_item_used
|
|
|
67
|
+SET
|
|
|
68
|
+ weight = 0
|
|
|
69
|
+WHERE
|
|
|
70
|
+ weight ISNULL;
|
|
|
71
|
+
|
|
|
72
|
+-- evaluation_item_used 修正rule的值
|
|
|
73
|
+UPDATE
|
|
|
74
|
+ evaluation_item_used
|
|
|
75
|
+SET
|
|
|
76
|
+ "rule" = '{}'
|
|
|
77
|
+WHERE
|
|
|
78
|
+ "rule" = 'null' |