20260304163000_AddRobotTaskHistoryTablesHotfix.cs
3.98 KB
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
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Rcs.Infrastructure.DB.MsSql;
#nullable disable
namespace Rcs.Infrastructure.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20260304163000_AddRobotTaskHistoryTablesHotfix")]
public class AddRobotTaskHistoryTablesHotfix : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(@"
CREATE TABLE IF NOT EXISTS robot_task_histories (
task_id uuid NOT NULL,
task_code character varying(50) NOT NULL,
task_name character varying(100),
robot_code character varying(50),
task_template_code character varying(50),
begin_location_code character varying(50),
end_location_code character varying(50),
status integer NOT NULL,
pause boolean NOT NULL DEFAULT FALSE,
priority integer NOT NULL DEFAULT 99,
source character varying(300),
relation character varying(300),
shelf_code character varying(50),
error_info text,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone,
archived_at timestamp without time zone NOT NULL,
CONSTRAINT ""PK_robot_task_histories"" PRIMARY KEY (task_id)
);
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'ak_task_history_task_code'
) THEN
ALTER TABLE robot_task_histories
ADD CONSTRAINT ""ak_task_history_task_code"" UNIQUE (task_code);
END IF;
END $$;
CREATE INDEX IF NOT EXISTS idx_task_history_archived_at ON robot_task_histories (archived_at);
CREATE INDEX IF NOT EXISTS idx_task_history_begin_location_code ON robot_task_histories (begin_location_code);
CREATE INDEX IF NOT EXISTS idx_task_history_end_location_code ON robot_task_histories (end_location_code);
CREATE INDEX IF NOT EXISTS idx_task_history_robot_code ON robot_task_histories (robot_code);
CREATE INDEX IF NOT EXISTS idx_task_history_status ON robot_task_histories (status);
CREATE INDEX IF NOT EXISTS idx_task_history_task_code ON robot_task_histories (task_code);
CREATE TABLE IF NOT EXISTS robot_sub_task_histories (
sub_task_id uuid NOT NULL,
task_code character varying(50) NOT NULL,
robot_code character varying(50),
begin_node_code character varying(50) NOT NULL,
end_node_code character varying(50) NOT NULL,
sequence integer NOT NULL,
status integer NOT NULL,
execution_count integer NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone,
archived_at timestamp without time zone NOT NULL,
CONSTRAINT ""PK_robot_sub_task_histories"" PRIMARY KEY (sub_task_id)
);
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'FK_robot_sub_task_histories_robot_task_histories_task_code'
) THEN
ALTER TABLE robot_sub_task_histories
ADD CONSTRAINT ""FK_robot_sub_task_histories_robot_task_histories_task_code""
FOREIGN KEY (task_code)
REFERENCES robot_task_histories(task_code)
ON DELETE CASCADE;
END IF;
END $$;
CREATE INDEX IF NOT EXISTS idx_sub_task_history_archived_at ON robot_sub_task_histories (archived_at);
CREATE INDEX IF NOT EXISTS idx_sub_task_history_begin_node_code ON robot_sub_task_histories (begin_node_code);
CREATE INDEX IF NOT EXISTS idx_sub_task_history_end_node_code ON robot_sub_task_histories (end_node_code);
CREATE INDEX IF NOT EXISTS idx_sub_task_history_robot_code ON robot_sub_task_histories (robot_code);
CREATE INDEX IF NOT EXISTS idx_sub_task_history_task_code ON robot_sub_task_histories (task_code);
CREATE INDEX IF NOT EXISTS idx_sub_task_history_task_sequence ON robot_sub_task_histories (task_code, sequence);
");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(@"
DROP TABLE IF EXISTS robot_sub_task_histories;
DROP TABLE IF EXISTS robot_task_histories;
");
}
}
}