feat(production): 修改订单流程卡死流程问题
This commit is contained in:
+43
-3
@@ -119,7 +119,7 @@ create table if not exists schema_version (
|
||||
);
|
||||
|
||||
insert into schema_version (id, version, description)
|
||||
values (1, 7, 'Quality query indexes')
|
||||
values (1, 10, 'Support reverse flip production checkpoints')
|
||||
on conflict (id) do update
|
||||
set version = excluded.version,
|
||||
description = excluded.description,
|
||||
@@ -151,6 +151,7 @@ create table if not exists production_runs (
|
||||
'RUNNING',
|
||||
'PAUSED',
|
||||
'RECOVERY',
|
||||
'STOPPING',
|
||||
'ERROR',
|
||||
'COMPLETED',
|
||||
'STOPPED'
|
||||
@@ -169,7 +170,7 @@ create table if not exists production_runs (
|
||||
|
||||
create unique index if not exists ux_production_runs_active_order
|
||||
on production_runs(order_id)
|
||||
where run_state in ('RUNNING', 'PAUSED', 'RECOVERY');
|
||||
where run_state in ('RUNNING', 'PAUSED', 'RECOVERY', 'STOPPING');
|
||||
|
||||
create index if not exists ix_production_runs_order_id
|
||||
on production_runs(order_id);
|
||||
@@ -177,6 +178,38 @@ on production_runs(order_id);
|
||||
create index if not exists ix_production_runs_workpiece_id
|
||||
on production_runs(current_workpiece_id);
|
||||
|
||||
-- Existing databases were created before STOPPING became a persisted run state.
|
||||
do $$
|
||||
declare
|
||||
target_table regclass := 'production_runs'::regclass;
|
||||
begin
|
||||
if exists (
|
||||
select 1 from pg_indexes
|
||||
where schemaname = current_schema()
|
||||
and indexname = 'ux_production_runs_active_order'
|
||||
and indexdef not like '%STOPPING%'
|
||||
) then
|
||||
drop index ux_production_runs_active_order;
|
||||
create unique index ux_production_runs_active_order
|
||||
on production_runs(order_id)
|
||||
where run_state in ('RUNNING', 'PAUSED', 'RECOVERY', 'STOPPING');
|
||||
end if;
|
||||
if exists (
|
||||
select 1 from pg_constraint
|
||||
where conrelid = target_table
|
||||
and conname = 'ck_production_run_state'
|
||||
and pg_get_constraintdef(oid) not like '%STOPPING%'
|
||||
) then
|
||||
alter table production_runs drop constraint ck_production_run_state;
|
||||
alter table production_runs add constraint ck_production_run_state
|
||||
check (run_state in (
|
||||
'RUNNING', 'PAUSED', 'RECOVERY', 'STOPPING',
|
||||
'ERROR', 'COMPLETED', 'STOPPED'
|
||||
));
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
-- Independent action recovery checkpoints (PostgreSQL 9.5 compatible).
|
||||
-- Keep NULL phases for historical rows: NULL does not mean NOT_SENT.
|
||||
do $$
|
||||
@@ -266,7 +299,7 @@ begin
|
||||
select *
|
||||
from (values
|
||||
('ck_production_runs_action_type',
|
||||
'action_type is null or action_type in (''PHOTO_MOVE'', ''VISION'', ''RACK_PICK'', ''FRONT_LOAD'', ''INSPECT'', ''FRONT_UNLOAD'', ''FLIP'', ''BACK_LOAD'', ''BACK_UNLOAD'', ''RACK_PLACE'')'),
|
||||
'action_type is null or action_type in (''PHOTO_MOVE'', ''VISION'', ''RACK_PICK'', ''FRONT_LOAD'', ''INSPECT'', ''FRONT_UNLOAD'', ''FLIP'', ''BACK_LOAD'', ''BACK_UNLOAD'', ''REVERSE_FLIP'', ''RACK_PLACE'')'),
|
||||
('ck_production_runs_action_phase',
|
||||
'action_phase is null or action_phase in (''NOT_SENT'', ''SENDING'', ''COMMAND_CONFIRMED'', ''FEEDBACK_RECEIVED'', ''SIGNALS_CLEARED'', ''STEP_COMMITTED'', ''RESULT_WRITING'', ''RESULT_CONFIRMED'', ''MODE_WRITING'', ''MODE_CONFIRMED'')'),
|
||||
('ck_production_runs_manual_decision',
|
||||
@@ -275,6 +308,13 @@ begin
|
||||
('ck_production_runs_action_lock_version', 'action_lock_version >= 0')
|
||||
) as constraints_to_add(constraint_name, check_expression)
|
||||
loop
|
||||
if rule.constraint_name = 'ck_production_runs_action_type' and exists (
|
||||
select 1 from pg_constraint
|
||||
where conrelid = target_table and conname = rule.constraint_name
|
||||
and pg_get_constraintdef(oid) not like '%REVERSE_FLIP%'
|
||||
) then
|
||||
alter table production_runs drop constraint ck_production_runs_action_type;
|
||||
end if;
|
||||
if not exists (
|
||||
select 1 from pg_constraint
|
||||
where conrelid = target_table
|
||||
|
||||
Reference in New Issue
Block a user